Tuesday, October 7, 2014

Share data among controllers

Use $ rootScope

var app = angular.module('mymodule',[]);
app.controller('Ctrl1', ['$scope','$rootScope',
  function($scope, $rootScope) {
    $rootScope.showBanner = true;
}]);

app.controller('Ctrl2', ['$scope','$rootScope',
  function($scope, $rootScope) {
    $rootScope.showBanner = false;
}]);

Source:
http://stackoverflow.com/questions/20181323/passing-data-between-controllers-in-angular-js



No comments: