angularjs入门基础一

app.controller('firstController',function($scope,$rootScope){

  $scope.name='张三'; 

 $rootScope.age='30'; 

}); 

app.controller('secondController',function($scope,$rootScope){

 // $scope.name='张三'; 

 $rootScope.age='30'; 

}); second

1:$rootScope 全局变量

2: secondController会继承到first中的name

3:依赖注入中代码压缩的问题 

app.controller("firstController",["$scope",function($scope){

  $scope.name="heqiang";

}]) 

4:run()

方法初始化全局的数据 ,只对全局作用域起作用 如$rootScope 

 var m1 = angular.module('myApp',[]);

  m1.run(['$rootScope',function($rootScope){

  $rootScope.name = 'hello';}]); 

原文地址:https://www.cnblogs.com/xqschool/p/6033548.html