我试图将$ scope变量值作为属性传递给自定义指令,但它不起作用。
下面是HTML代码:
<ul ng-repeat="q in questions">
<li>
{{q.question}}
<check-list name="{{q.id}}"></check-list>
</li>
</ul>
该指令是<check-list name={{q.id}}></check-list>
,这里是指令代码:
app.directive('checkList',function(){
return {
restrict:'E',
template: function(elem,attrs){
console.log(attrs.name);
return '</br> <input type="radio" /> Yes </br> <input type="radio" /> No'
},
link:function(scope,elem,attrs){
}
};
})
我登录属性attrs.name
但我得到的价值是"{{q.id}}"
而不是实际值q.id
'<检查利st name =“{{q.id}}”>'似乎你想念双引号? – Rebornix 2015-02-10 06:49:27
现在我得到'{{q.id}}' – iJade 2015-02-10 06:50:32
顺便说一句,你可以参考这个[问题](http://stackoverflow.com/questions/28394118/angularjs-directive-scope-not-resolved-attr-name -is-not-defined-error/28394192#28394192),它可以解决你的问题。 – Rebornix 2015-02-10 06:50:57