AngularJS 模块中的run方法

Posted 铭绘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AngularJS 模块中的run方法相关的知识,希望对你有一定的参考价值。

AngularJS中的run方法初始化全局数据,只对全局作用域起作用,如$rootScope.多个控制器之间可以共享数据,如下代码所示:

 

[html] 
 
  1. <script type="text/javascript">    
  2.           var m1 = angular.module(‘myApp‘,[]);  
  3.           m1.run([‘$rootScope‘,function($rootScope){  
  4.           $rootScope.name = ‘hello‘;  
  5.            }]);    
  6.           console.log( m1 );  
  7.     </script>   

以上是关于AngularJS 模块中的run方法的主要内容,如果未能解决你的问题,请参考以下文章