In app.js
'use strict'// run 的作用表示初始化执行,也就是所以页面加载之前执行angular.module('app',['ui.router']).run(['$rootScope',function($rootScope){ //比如说我们在所有页面初始化执行之前添加一个im属性,那么之后创建的所有$scope对象因为都是它的子孙对象,都会有im这样的属性 $rootScope.im = function(){ console.log('im'); } }]);
This is the biggest role of $rootScope, which is equivalent to defining public functions and variables. However, we still recommend using services to generally define public functions.
The above is the detailed content of Common usage of $rootScope. For more information, please follow other related articles on the PHP Chinese website!