javascript - Angularjs child cannot update parent variable -


i have 2 controllers:

app.controller('maincontroller',['$scope','$templatecache','$route','$location',function($scope, $templatecache,$route,$location) {          $scope.clear = function(){             //console.log("clicked");             //console.log($route.current.originalpath);             $( "#activewarning" ).show();             $templatecache.removeall();             $route.reload();             $location.path( $route.current);         } }]); 

and

app.register.controller('settingscontroller', function ($scope) {     $(document).ready(function(){         $("#btnsubmitaccountsetting").click(function(e){             e.preventdefault();             swal({                     title: 'are sure?',                     text: 'your account switched unverified until verify account updated documents.',                     type: 'warning',                     showcancelbutton: true,                     confirmbuttoncolor: '#3085d6',                     cancelbuttoncolor: '#d33',                     confirmbuttontext: 'yes, update it!',                     closeonconfirm: false                 },                 function() {                     console.log("clicked");                     $scope.name = "toto";                     $scope.$parent.name="toto";                     console.log("all");                     $scope.$digest();                     $scope.$parent.name="toto";                 });         });     }); }); 

the settingcontroller being child of maincontroller. issue not being able update name variable set in maincontroller via

<data ng-controller="maincontroller" ng-init="name = '{{$basicinfo["name"]}}'"/>

i tried $scope.$parent.name="toto"; no help. tired add setters in maincontroller didnt helped.

only variable in child controller updating, not parent controller.

how can update name variable in parent controller child controller. within ng-view directive?

structure of html

<!doctype html> <html ng-app="app">   <head>     <meta charset="utf-8">     <meta http-equiv="x-ua-compatible" content="ie=edge">     <title> dashboard</title>     <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">   </head>   <body class="hold-transition skin-blue sidebar-mini" ng-controller="maincontroller">     <data ng-controller="maincontroller" ng-init="name = 'kheshav'"/>     <dava ng-controller="maincontroller" ng-init="surname = 'sewnundun'"/>    <script src="http://maurijob.devlocal/libraries/js/jquery-ui-1.11.1/jquery-ui.min.js"></script> <script src="http://maurijob.devlocal/libraries/js/angularjs/angular-1.4.8.min.js"></script> <script src="http://maurijob.devlocal/libraries/js/angularjs/angular-1.4.8-route.min.js"></script> <script src="http://maurijob.devlocal/libraries/myangular/app.js"></script>       <div class="content-wrapper"   ng-view>      </div><!-- ./wrapper -->  </body> </html> 

update

removed jquery in controller:

app.register.controller('settingscontroller', function ($scope) {     $scope.modal = function(){             swal({                     title: 'are sure?',                     text: 'your account switched unverified until verify account updated documents.',                     type: 'warning',                     showcancelbutton: true,                     confirmbuttoncolor: '#3085d6',                     cancelbuttoncolor: '#d33',                     confirmbuttontext: 'yes, update it!',                     closeonconfirm: false                 },                 function() {                     console.log("clicked");                     $scope.name = "toto";                     $scope.$parent.name="toto";                     console.log("all");                     $scope.$digest();                     $scope.$parent.name="toto";                 });     }  }); 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -