app.controller('ParentController', function($scope){
$scope.parentPrimitive = "some primitive"
$scope.parentObj={};
$scope.parentObj.parentProperty="some value";
});
app.controller('ChildController', function($scope){
$scope.parentPrimitive="this will not modify the parent";
$scope.parentObj.parentProperty="this will modify the parent";
});
如果想使用原型数据:
1. 在子scope种使用$parent.parentPrimitive -- 阻止子Scope创建属性
2. 在父scope中定义函数,让子scope调用
四种scope:
- 普通进行原型继承的 Scope —— ng-include, ng-switch, ng-controller, directive with
scope: true - 普通原型继承的 Scope 但拷贝赋值 —— ng-repeat。 每个 ng-repeat 的循环都创建新的子 Scope,并且子 Scope 总是获得新的属性。
- 独立的 isolate scope —— directive with
scope: {...}。它不是原型继承,但 ‘=’, ‘@’ 和 ‘&’ 提供了访问父 Scope 属性的机制。 - transcluded scope —— directive with
transclude: true。它也遵循原型继承,但它同时是任何 isolate scope 的兄弟。
No comments:
Post a Comment