Tag: rootcope

Angularjs – $ rootScope中的指令链接函数

我在问这个问题,因为我不太清楚如何将rootcope作为依赖传递给指令 我有一个指令,需要显示$ rootScope的一些信息… 我以为我需要将$ rootScope传递给一个指令,但是当我写这样的指令似乎工作。 .directive("myBar", function () { return { restrict: "E", transclude: true, replace: true, template: '<div>' + '<span ng-transclude></span>' + '{{rsLabels.welcome}} {{rsUser.firstName}}!' + '</div>' } }) 我什么时候需要这样做? .directive("myBar", function ($rootScope) { return { restrict: "E", transclude: true, replace: true, template: '<div>' + '<span ng-transclude></span>' + '{{rsLabels.welcome}} {{rsUser.firstName}}!' + '</div>' } }) 我可以和如何使用rootScope,如果我需要它在指令的链接function […]

为什么我们在AngularJS中使用$ rootScope。$ broadcast?

试图findAngularJS $rootScope.$broadcast一些基本信息,但是AngularJS文档没有什么帮助。 简单地说,为什么我们使用这个? 此外,在John Papa的Hot Towel模板中,在名为$broadcast的通用模块中有一个自定义函数: function $broadcast() { return $rootScope.$broadcast.apply($rootScope, arguments); } 我不明白这是做什么。 所以这里有几个基本的问题: 1) $rootScope.$broadcast做什么? 2) $rootScope.$broadcast和$rootScope.$broadcast.apply是什么区别?

如何在Angular中使用$ rootScope来存储variables?

如何使用$rootScope将variables存储在控制器中,我想稍后在另一个控制器中访问? 例如: 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 }); 我将如何做到这一点?