如何在Angular中使用$ rootScope来存储变量? - How do I use $rootScope in Angular to store variables?

10/14 16:46
阅读数 0

问题:

How do I use $rootScope to store variables in a controller I want to later access in another controller? 如何使用$rootScope将变量存储在我想稍后在另一个控制器中访问的控制器中? For example: 例如:

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
});

How would I do this? 我该怎么做?


解决方案:

参考一: https://en.stackoom.com/question/1HDk1
参考二: https://stackoom.com/question/1HDk1
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部