问题描述
如何prevent指令与transclude创造新的领域?
How to prevent directive with transclude to create new scopes?
这我不能绑定任何因与红色边框所示的新范围。
This jsfiddle I cant bind anything due to the new scopes illustrated with red borders.
HTML:
<div ng-app="components">
<input ng-model="var">
<block>
123
<input ng-model="var">
</block>
</div>
JavaScript的:
angular.module('components', []).directive('block',function(){
return{
scope:false,
replace:true,
restrict:"E",
transclude:true,
template:'<div class="block" ng-transclude></div>',
link:function(scope, el, attrs, ctrl){
}
}
});
CSS:
.ng-scope{
border:1px solid red;
margin:10px;
}
推荐答案
它实际上是预期的行为作为这里所说(NG-transclude创建一个子范围内):https://github.com/angular/angular.js/issues/1056
这里讨论:https://groups.google.com/forum/#!msg/angular/45jNmQucSCE/hL8x48-JfZIJ
It is actually expected behavior as stated here (ng-transclude create a child scope): https://github.com/angular/angular.js/issues/1056and discussed here: https://groups.google.com/forum/#!msg/angular/45jNmQucSCE/hL8x48-JfZIJ
您可以通过在范围(obj.var)在对象上设置一个成员想在这个小提琴解决此//jsfiddle.net/rdarder/pnSNj/10/
You can workaround this by setting a member on an object in the scope (obj.var) like in this fiddle: http://jsfiddle.net/rdarder/pnSNj/10/
这篇关于AngulaJS指令transclude范围=假?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!