Janez Novak
Janez Novak

Reputation: 13

Access local template variable using interpolation inside *ngIf, Angular 2

Let's say I have this situation;

<div *ngFor="item of items; let i = index;">
  <div *ngIf="variable{{i}}">show if variable{{i}} is true</div>
</div>

And I have defined variables "variable0", "variable1",... How do I access variables in such way using interpolation in *ngIf? I know *ngIf is a separate template, that's why it can't see the "i" variable, but how can I pass it into the *ngIf template and use it?

Upvotes: 1

Views: 1159

Answers (1)

yurzui
yurzui

Reputation: 214047

I assume this should work

*ngIf="this['variable' + i]"

Plunker

Upvotes: 3

Related Questions