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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -