I am new to angular , can someone tell me if I can use variable inside variable in angular. Explaination:
I am creating one dropdown input component where it will make api call to get data.
There is an @Input() selector:string = ""
which will tell what to select from data
Inside template it will run *ngFor
loop, then inside html I want to display as kind of like that:
<option *ngFor="let item of data" [value]="item.id">
{{ item.{{selector}} }}
</option>
In other module it will be used as:
- In one module
<app-input [selector]="'name'"></app-input>
- Another one.
<app-input [selector]="'id'"></app-input>
How Can I use selector
inside this any way?
CodePudding user response:
{{ item[selector] }}
use the bracket syntax for accessing a property with a variable key.