Issue
I am using Angular 13 and I'm looking for a way to have a list or components load by reading the component names from a json file.
For example..I have a json file with the names of the components that I want to load into my app.component.html
componentListToLoad = [
  {
    "name": "Component1"
  },
  {
    "name": "Component2"
  }
]
Then in a for loop I would get the two components loaded.
app.component.html
<div *ngFor="let list of componentListToLoad">
  // Load the component list
</div>
How can I do this in Angular?
Solution
In app.component.ts file declare componentListToLoad array
  let componentListToLoad:any = [
  {
    "name": "Component1"
   },
  {
   "name": "Component2"
   }
  ];
In app.component.html file add following code
 <ng-container *ngFor="let list of componentListToLoad">
    <div>{{ list.name }}</div>
  </ng-container>
                        Answered By - pramod24
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.