简体   繁体   中英

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.

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.

Why this ditching is present in 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. That should do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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