我在第一行代码中有 ng-repeat,在下一行我需要根据我在 ng-repeat 中得到的内容创建一个动态变量。
代码看起来像这样:
<div ng-repeat="head in arrayofhead">
<span ng-if="canIbecreated_{{head}}">I am created!!</span>
</div>
在哪里
arrayofhead = ["1","2","3"];
但这会产生错误,而同样我可以轻松地传递 {{$index}}。
为什么 Angularjs 中会出现这种放弃?
我会在 Controller 上做
var canIbecreated_1="false";
var canIbecreated_2="true";
var canIbecreated_3="false";
打包而不是创建跨度。
最佳答案
... ng-if="someFunc(head)" ...
在 ng-repeat
block 内。这应该可以解决问题。
关于javascript - 如何在 ng-if 中传递 ng-repeat 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26422552/