javascript - How to share the $scope variable of one controller with another in AngularJS? -


i have this:

app.controller('foo1', function ($scope) {   $scope.bar = 'foo'; }); app.controller('foo2', function ($scope) {   // want access $scope of foo1 here, access bar }); 

how accomplish this?

you use angular service share variable acrosss multiple controllers.

angular.module('myapp', []) .service('user', function () {     return {}; }) 

to share data among independent controllers, services can used. create service data model needs shared. inject service in respective controllers.

function controllera($scope, user) {     $scope.user = user;     $scope.user.firstname = "vinoth"; }  function controllerb($scope, user) {     $scope.user = user;     $scope.user.lastname = "babu";         } 

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 ? -