Reputation: 467
I have a list of options called header
to show in a dropdown list. I also have another list, table_settings['tags']
, and I want the i'th element of header
in the dropdown list if the i'th element of table_settings['tags']
is 'Num'
.
Currently my code is:
<div *ngIf="header">
<select (change)-"selectTarget($event)">
<option *ngFor="let option of header; let i=index" value="{{i}}">
<ng-template *ngIf="table_settings['tags'][{{i}}]=='Num'">
{{ option }}
</ng-template>
</option>
</select>
</div>
But this is throwing all sorts of errors at the console
Upvotes: 3
Views: 2663
Reputation: 735
<div *ngIf="header">
<select (change)-"selectTarget($event)">
<ng-container *ngFor="let option of header; let i=index" value="{{i}}">
<option *ngIf="table_settings['tags'][i]=='Num'">
{{ option }}
</option>
</ng-container>
</select>
<div>
Upvotes: 0
Reputation: 1458
Interpolation ({{}}) allows you to incorporate calculated value(strings) into the text between HTML element tags and attribute assignments.
In your case, you don't need to calculate anything as you already have i
handy.
Solution
<div *ngIf="header">
<select (change)-"selectTarget($event)">
<option *ngFor="let option of header; let i=index" value="{{i}}">
<ng-template *ngIf="table_settings['tags'][i]=='Num'">
{{ option }}
</ng-template>
</option>
</select>
Upvotes: 1
Reputation: 1245
<div *ngIf="header">
<select (change)-"selectTarget($event)">
<option *ngFor="let option of header; let i=index" value="{{i}}">
<ng-template *ngIf="table_settings['tags'][i]=='Num'">
{{ option }}
</ng-template>
</option>
</select>
Upvotes: 1