如何在Angular中使用$ rootScope来存储变量?如何使用$rootScope我想稍后在另一个控制器中访问的控制器中存储变量?例如:angular.module('myApp').controller('myCtrl', function($scope) {
var a = //something in the scope
//put it in the root scope});angular.module('myApp').controller('myCtrl2', function($scope) {
var b = //get var a from root scope somehow
//use var b});我该怎么做?
3 回答
幕布斯6054654
TA贡献1876条经验 获得超7个赞
angular.module('myApp').controller('myCtrl', function($scope, $rootScope) { var a = //something in the scope //put it in the root scope $rootScope.test = "TEST"; });angular.module('myApp').controller('myCtrl2', function($scope, $rootScope) { var b = //get var a from root scope somehow //use var b $scope.value = $rootScope.test; alert($scope.value); // var b = $rootScope.test; // alert(b); });
- 3 回答
- 0 关注
- 989 浏览
添加回答
举报
0/150
提交
取消