angularjs - Propagating model changes to a Parent Controller in Angular -


i have angularjs application , try simulate asana.com feature.

the scenario following:

asana

i have maincontroller application in body tag, , inside controller populate names in sidebar:

.controller('maincontroller', ['$scope', 'namesservice', function($scope, namesservice) {     $scope.names = namesservice.query();     ... }; 

when click on name (for example, anna), application change route , in inject name-edit.html template in ng-view, represented content area on picture above. have input used change anna carol , update button. when hit update button, fires function updates in database, changes anna carol in content area (represented yellow arrow position) doesn't change red arrow position in sidebar.

i tried call following code again inside success update callback, doesn't work

$scope.names = namesservice.query(); 

i'd know how propagate child controller parent controller, changing anna carol inside $scope.names. possible this, without reloading $scope.names?

you use event system of angular using $scope.$emit('eventname', eventdata) un child controller pass data on hierarchy.

//child, assuming have promise callback namesservice.query().then(function(data){    $scope.$emit('eventname', data) }) 

and in parent controller have following

//parent $scope.$on('eventname', function(event, data){    $scope.names = data; }) 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -