rootscope

Why using $rootScope with functions is not recommended?

眉间皱痕 提交于 2019-11-26 08:35:15
问题 While am looking into the FEQs of Angularjs I\'ve seen below article: $rootScope exists, but it can be used for evil Scopes in Angular form a hierarchy, prototypally inheriting from a root scope at the top of the tree. Usually this can be ignored, since most views have a controller, and therefore a scope, of their own. Occasionally there are pieces of data that you want to make global to the whole app. For these, you can inject $rootScope and set values on it like any other scope. Since the

Why do we use $rootScope.$broadcast in AngularJS?

ⅰ亾dé卋堺 提交于 2019-11-26 02:41:57
问题 Tried to find some basic information for AngularJS $rootScope.$broadcast , But the AngularJS documentation doesn\'t help much. In easy words why do we use this? Also, inside John Papa\'s Hot Towel template there is a custom function in the common module named $broadcast : function $broadcast() { return $rootScope.$broadcast.apply($rootScope, arguments); } I did not understand what this is doing. So here are couple of basic questions: 1) What does $rootScope.$broadcast do? 2) What is the

How do I use $rootScope in Angular to store variables?

蹲街弑〆低调 提交于 2019-11-26 00:35:49
问题 How do I use $rootScope to store variables in a controller I want to later access in another controller? 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? 回答1: Variables set at the root-scope are available to the controller scope via prototypical