Home > Web Front-end > JS Tutorial > Common usage of $rootScope

Common usage of $rootScope

一个新手
Release: 2017-09-23 10:07:41
Original
1355 people have browsed it

In app.js

'use strict'// run 的作用表示初始化执行,也就是所以页面加载之前执行angular.module('app',['ui.router']).run(['$rootScope',function($rootScope){
     //比如说我们在所有页面初始化执行之前添加一个im属性,那么之后创建的所有$scope对象因为都是它的子孙对象,都会有im这样的属性
     $rootScope.im = function(){
         console.log('im');
     }
}]);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template