【发布时间】:2017-08-22 08:54:30
【问题描述】:
我正在处理一个指令,并且我正在使用 transclude,因此在其中使用了指令使用的 inner element。
假设这是我的指令观点:
<div>
<div ng-repeat="opt in options">
<ng-transclude></ng-transclude>
</div>
</div>
指令:
app.directive("myDirective", function(){
return {
restrict: "E",
transclude: true,
templateUrl: 'my-directive.html',
scope: {
options: '='
}
};
});
还有一个简单的用法:
<my-directive options="someOptions">
<p>{{someObject[$parent.opt]}}</p>
</my-directive>
这很好用。我对这个解决方案的问题是 $parent.opt 不是很可读和清晰......
还有其他选择吗?
谢谢
【问题讨论】:
标签: angularjs angularjs-scope angularjs-ng-transclude