angularjs - How to force parent controller to reload data? -
i trying force parent controller reload data after update data in child controller. html :
<div ng-controller='parentctr'> {{data}} <mydirective></mydirective> </div>
the data in parentctr server calling service this:
function parentctr(){ $scope.data=someservice.getdate(); } in mydirective: function childctr(){ // update data , save in same server. someservice.update(data); }
what need after someservice.update() success, need parent level refresh data , show update info.
you can way. emit message when call success , listen message in parent controller refresh state or page.
function parentctr($scope,$state){ $scope.data=someservice.getdate(); $scope.$on('refreshparent', function(){ $state.reload(); //reload state }) } function childctr($scope){ // update data , save in same server. someservice.update(data).then(function(){ //emit message when success $scope.$emit('refreshparent'); }); }
Comments
Post a Comment