Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use variable inside variable in angular template?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<option *ngFor="let item of data" [value]="item.id">
        {{ item.{{selector}} }}
 </option>

In other module it will be used as:

  1. In one module <app-input [selector]="'name'"></app-input>
  2. Another one. <app-input [selector]="'id'"></app-input>

How Can I use selector inside this any way?

>Solution :

{{ item[selector] }}

use the bracket syntax for accessing a property with a variable key.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading