listener - AngularJS - Refresh all instances of the app on $emit -


i've angularjs app. i've page following template , controller:

<div ng-controller="parentctrl">     <p>{{food}}</p>     <div ng-controller="childctrl">         <button ng-click="onbtnclk()">{{buttontitle}}</button>     </div> </div> 

the 2 controllers:

app.controller('parentctrl', parentctrl); parentctrl.$inject = ['$scope','$rootscope']; function parentctrl($scope,$rootscope) {     $rootscope.food = "hi"     $rootscope.$on("update_parent", function(event,msg) {         $rootscope.food = msg;         console.log("witnessed")     }); }  app.controller('childctrl', childctrl); childctrl.$inject = ['$scope','$rootscope'];  function childctrl($scope,$rootscope) {     $scope.buttontitle="update parent"     $scope.onbtnclk = function() {         $rootscope.$emit("update_parent","updatedyy");         console.log($rootscope)     }; } 

so basically, i've parent , child controller; clicking button in child controller emits event message "updatedyy". picked $on in parent controller sets value of $rootscope.food message value.

now question is, possible see value change of variable in instances of app? example, if i've app (running on tomcat server) open in 2 tabs in browser, , click on button - possible changed value in other tab well?


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -