Reputation: 10939
Is there a way to dynamically create a html tag in components template?
Something like this
template:`<{{custom_tag}} [info]="info"></{{custom_tag}}>`
...
this.custom_tag="example";
this.info={};
Generated html will be something like this
<example info="..."></example>
Upvotes: 1
Views: 7123
Reputation: 804
Sorry for the delay, but I'm adding my response:
Create a new component and now you can use that component selector tag itself inside wherever needed.
like;
@Component({
selector: 'app-example',
})
export class ExampleComponent implements OnInit {}
Use selector as:
<app-example></app-example>
Pass parameters to the new component as:
<app-example [param]="abc"></app-example>
This input param needs to be identified with the same identifier 'param' using @input() property.
Upvotes: -2
Reputation: 31
I had the same problem, I resolved with a directive to replace the tag:
https://stackoverflow.com/a/42049947/7383715
Upvotes: 3