我正在尝试使用指令进行模板化,但不幸的是,每个指令似乎都为模板和控制器/链接功能设置了单独的范围。
plnkr的示例:
<body ng-app="App">
<h2>Directive with Isolating Scope</h2>
<isolating some-value="isolated">{{someValue}}</isolating>
<h2>Directive with Shared Scope</h2>
<sharing some-value="shared">{{someValue}}</sharing>
</body>
var app = angular.module('App', []);
app.directive('isolating', function(){
return {
'restrict': 'E',
'scope': {
'someValue': '@'
},
'transclude': true,
'template': '<div ng-transclude></div>',
'link': function(scope, element, attrs){
scope.someValue = attrs.someValue;
}
};
});
app.directive('sharing', function(){
return {
'restrict': 'E',
'transclude': true,
'template': '<div ng-transclude></div>',
'link': function(scope, element, attrs){
scope.someValue = attrs.someValue;
}
};
});
我在 Batarang 中看到的内容:(括号中的指令名称)
< Scope (002)
< Scope (003) <= (isolating) contains the isolated scope
< Scope (004) <= (isolating) contains the template scope
< Scope (005) <= (sharing) contains the shared scope
如何将隔离范围 003 用于模板?Scope 004 似乎完全没有必要。
AngularJS 版本是 1.2.0-rc3。