[英]Angular passing parameters to a directive
我有以下HTML,运行以下指令。 我需要将loop
参数传递给指令模板。 但是由于某种原因,它不起作用。 为什么?
的HTML
<ul>
<list-element loop></list-element>
</ul>
角度
angular.module('myApp', []).directive('listElement', function(){
return {
templateUrl: 'list-element.html',
scope: {},
link: {
scope.loop : vm.list
}
};
});
模板
<li ng-repeat="(slug, label) in loop">
<strong>{{ slug }}</strong> - {{ label }}
</li>
我认为您想要的是:
HTML:
<ul>
<list-element loop="vm.list"></list-element>
</ul>
角度:
angular.module('myApp', []).directive('listElement', function(){
return {
templateUrl: 'list-element.html',
scope: {
loop: '='
}
};
});
我正在猜测loop =“ vm.list”,因为我不知道其余的代码。 但想法是,您要将对象作为名为“ loop”的属性传递。
尝试这个
的HTML
<ul>
<list-element loop ></list-element>
</ul>
角度指令
angular.module('myApp', []).directive('listElement', function(){
return {
templateUrl: 'list-element.html',
scope: {
},
link: function (scope) {
scope.loop = vm.list
}
};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.