A
A
Andrello2013-12-22 19:56:17
JavaScript
Andrello, 2013-12-22 19:56:17

How to pass $scope.var between controllers?

How is the transfer of data to $scope between controllers implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maxaon, 2013-12-22
@Andrello

Mostly through services. If the scopes are nested, you can refer to the parent in the child

G
GM2mars, 2013-12-23
@GM2mars

Through the global scope $rootScope:

app.controller('oneCtrl', ['$scope','$rootScope', function($scope, $rootScope) {
   $rootScope.var=1;
}]);

app.controller('twoCtrl', ['$scope','$rootScope', function($scope, $rootScope) {
   console.log($rootScope.var);     //1
}]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question