单独的范围我想使用的模板的指令,但不幸的是每个指令出现设置模板和控制器/链接功能的个人范围。在plnkrAngularJS:指令使用模板和控制器/链接
例子:
<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的模板?范围004似乎完全没有必要。
AngularJS版本是1.2.0-rc3。
好的,好像我真的简化了我的例子太多了。在我的应用程序中,我嵌套了与上述类似的多个指令,并希望传递父级作用域的某些部分,同时从相同的指令中添加新变量,因为它们在更深的嵌套级别上是必需的。所以我真的需要将隔离的控制器/链接范围传递给transcluded部分并从那里访问它。 – Energiequant