[英]is it possible to pass a json object with vars as an angularjs directive param?
here is how I am trying now: 这是我现在正在尝试的方法:
<ul
class="list"
list query="
{
'people': [{'people.id': '+id_+' }],
}
}"
>
<!-- ... -->
on the directive I do: 在指令我做:
var query = scope.$eval(attrs.query);
but by logging this variable I can see that the '+id_+' variable is not 'replaced' it's value. 但是通过记录此变量,我可以看到“ + id_ +”变量没有被“替换”,而是它的值。
I know there are many other ways of achieving the same resilt, but I feel like this one would be the most dynamic for at least this situation. 我知道还有很多其他方法可以实现相同的重铺效果,但是我觉得至少在这种情况下,这种方法是最有活力的。
You need to evaluate the the value of _id
when you pass it in as an attribute: {{_id}}
, see this plunk . 你需要评估的价值_id
当你把它作为一个属性{{_id}}
看到这个普拉克 。 However for the sake of readability I would avoid passing in Json objects like that into a directive, place that object on your controllers scope and pass that variable to the directive. 但是,出于可读性考虑,我会避免将类似的Json对象传递到指令中,将该对象放在控制器作用域中,并将该变量传递给指令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.