Problem Statement: I'm working on one of the angular applications. In this application, I've 4 components named as below,
- common-component
- box-one-component
- box-two-component
- box-three-component
Now, the "common-component" is responsible for rendering the rest of the components inside it by iterating over an array from it's ".ts" file. So we have below array of object which gives us the selector name for those 3 components.
[
{'componentName': "Box One", 'selector': "app-box-one"},
{'componentName': "Box Two", 'selector': "app-box-two"},
{'componentName': "Box Three", 'selector': "app-box-three"}
]
Now, I used ngFor to iterate over an array as below,
<div *ngFor="let com of components;">
<com.selector> </com.selector> // not giving selector name
</div>
Now, the problem is, <com.selector> </com.selector>
statement is unable to get the selector name from an object and that is obvious because in angular we use string interpolation as {{com.selector}}
to extract the data.
But, the problem is, that we can not use interpolation in the HTML Tag angel bracket. So, if I write something like <{{com.selector}}>
</{{com.selector}}>
then I get the error on the browser console window.
So, how can we extract the selector name in the HTML Tag angel bracket from each object that we are iterating over?
Expected Output after every iteration of for loop:
<div>
<app-box-one> </app-box-one>
// <app-box-two> </app-box-two>
// <app-box-three> </app-box-three>
</div>