I've an angularJS app. I've a page with the following template and
controller:
<div ng-controller="ParentCtrl">
<p>{{food}}</p>
<div ng-controller="ChildCtrl">
<button ng-click="onBtnClk()">{{buttonTitle}}</button>
</div></div>
The two 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 a parent and a child controller; Clicking the button in
the child controller emits an event with the message "updatedyy". This is
picked up the $on in the parent controller which sets the value of
$rootScope.food to the message value.
Now my question is, is it possible to see this value change of a variable
in all instances of the app? For example, if I've the app (running on a
Tomcat server) open in two tabs in my browser, and I click on the button -
is it possible to get a changed value in the other tab as well?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.