Reputation:
I'm attempting to create the following HTML element in my app.component.ts file:
<a *ngFor="let ver of versionList">{{ver}}</a>
The issue I'm running into is adding the *ngFor
to the element. I've tried using:
const a = this.renderer.createElement('a');
this.renderer.setProperty(a, '*ngFor', 'let ver of versionList');
and
const a = this.renderer.createElement('a');
this.renderer.setAttribute(a, '*ngFor', 'let ver of versionList');
with no luck. I haven't been able to find any references for dynamically adding *ngFor
in the documentation so I'm wondering if this is possible?
renderer is declared in constructor as: private renderer: Renderer2
Angular version: 8.2.2
Upvotes: 1
Views: 483
Reputation: 2926
It is not possible as *ngFor
should be compiled by Angular. But why do you need that?
Usually it is enough to add it to HTML and set *ngIf="versionList && versionList.length > 0"
Upvotes: 1