我正在尝试使用指令创建多个标签并将其附加到<div>
如下所示:
module.directive('createControl', function(){
return function(scope, element, attrs){
console.log(attrs.createControl); // undefined
}
});
<div class="control-group" ng-repeat="(k, v) in selectedControls">
<div create-control="{{ v.type }}"></div>
</div>
在 attrs 中我有这样的结构:
$$element: b.fn.b.init[1]
$$observers: Object
$attr: Object
createControl: "date"
style: "margin-right: 15px"
__proto__: Object
但是当我尝试使用attrs.createControl
I get undefined
我不明白为什么。实际问题:如何将范围变量传递给指令?
app.directive('createControl', function() {
return {
scope: {
createControl:'='
},
link: function(scope, element, attrs){
element.text(scope.createControl);
}
}
})
<div class="control-group" ng-repeat="v in [{type:'green'}, {type:'brown'}]">
<div create-control="v.type"></div>
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)