var app = angular.module('myApp', []);
app.run(function ($rootScope) {
// use .run to access $rootScope
$rootScope.rootProperty = 'root scope';
});
app.controller("ParentCtrl", ParentCtrlFunction);
app.controller("ChildCtrl", ChildCtrlFunction);
function ParentCtrlFunction($scope) {
// use .controller to access properties inside ng-controller
//in the DOM omit $scope, it is inferred based on the current controller
$scope.parentProperty = 'parent scope';
}
function ChildCtrlFunction($scope) {
$scope.childProperty = 'child scope';
//just like in the DOM, we can access any of the properties in the
//prototype chain directly from the current $scope
$scope.fullSentenceFromChild = 'Same $scope: We can access: ' +
$scope.rootProperty + ' and ' +
$scope.parentProperty + ' and ' +
$scope.childProperty;
}
例如。https://github.com/shekkar/ng-book/blob/master/7_beginning-directives/current-scope-introduction.html
这是一个简单的流程,我们有rootScope,parentScope,childScope。在每个部分中我们都分配了相应的范围变量。我们可以访问parentScope中的$rootScope,childScope中的rootScope和parentScope。