Reputation: 1064
<div *ngFor="let t of {{randomName}}"></div>
I want to pass the array name dynamically, i tried above code but i got error.
Thanks for answers but i have to update the question with my scenario
<div formArrayName="{{obj.key}}">
<div *ngFor="let t of formGrp.controls.{{obj.key}}.controls"></div>
</div>
I am creating form array dynamically and it can have any name depending on schema. I am able to bind that dynamic name to formArrayName as it supports interpolation but i need same behaviour on loop also
Upvotes: 0
Views: 2081
Reputation: 214345
It should be easy by using square brackets notation:
<div *ngFor="let t of formGrp.controls[obj.key].controls"></div>
^^^^^^^^^
Upvotes: 4
Reputation: 615
<div *ngFor="let t of dynamicArr"></div>
What you can do is set the Array dynamically in your component. Rather than using string interpolation.
export class SomeClass {
dynamicArr:[];
updateArr(){
// some logic
return this.dynamicArr = dynamic Array
}
}
Upvotes: 2
Reputation: 1976
<div *ngFor="let t of getTheData()"></div>
getTheData
is a method in your component that returns the data
Check the example here https://plnkr.co/edit/Ma66tJhpldYY4GuuM3uU?p=preview in the .component.ts
Upvotes: 2