<!-- 任何具有ng-app属性的DOM元素将被标记为$rootScope的起始点。 -->
<!-- ng-controller则会以$rootScope或另外一个ng-controller的作用域为原型创建新的子作用域 -->
<!-- {{someBareValue }} -->
{{ modal.someBareValue }}
<button ng-click="someAction()">Communicate to child</button>
<div ng-controller="ChildController">
<!-- {{someBareValue }} -->
{{ modal.someBareValue }}
<button ng-click="childAction()">Communicate to parent</button>
</div>
.controller('ChildController', ChildController)
ChildController.$inject = ['$scope', '$timeout', '$parse', '$ionicModal'];
function ChildController($scope, $timeout, $parse, $ionicModal){
$scope.childAction = function() {
// 在ChildController中设置{{ someBareValue }}
// $scope.someBareValue = 'hello human, from child';
$scope.modal.someBareValue = 'hello human, from child';
};
}
父作用域
$scope.modal= {someBareValue :'hello computer'};
// 设置 $scope 本身的操作,这样没问题
$scope.someAction = function() {
// 在SomeController和ChildController中设置{{ someBareValue }}
// $scope.someBareValue = 'hello human, from parent';
// 如果改成对象,它会通过引用进行共享,因此在子$scope中修改属性也会修改父$scope中的这个属性
$scope.modal.someBareValue = 'hello human, from parent';
};