简体   繁体   English

如何在ng-if中传递ng-repeat变量?

[英]How to pass a ng-repeat variable in ng-if?

I have ng-repeat in first line of code , in the next line I need to create a dynamic variable based on what I get in ng-repeat. 我在第一行代码中使用了ng-repeat,在下一行中我需要根据ng-repeat中的内容创建一个动态变量。

code would look something like this: 代码看起来像这样:

<div ng-repeat="head in arrayofhead">
  <span ng-if="canIbecreated_{{head}}">I am created!!</span>
</div>

where 哪里

arrayofhead = ["1","2","3"];

but this produces an error while similarly I can pass {{$index}} in this easily. 但这会产生错误,同样我可以很容易地传递{{$ index}}。

Why this ditching is present in Angularjs? 为什么Angularjs会出现这种开沟?

on Controller I would do 在控制器上我会这样做

var canIbecreated_1="false";
var canIbecreated_2="true";
var canIbecreated_3="false";

To crate and not to create the span. 箱子而不是创造跨度。

... ng-if="someFunc(head)" ...

Inside the ng-repeat block. ng-repeat块内。 That should do the trick. 这应该够了吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM