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';}]);