Angular *ngFor Directive comes under the structure directive and it works like a for of loop. *ngFor loop is used in the Component HTML file to display the data.
Syntax:-
*ngFor="let element of elementArray"
Note:- You can declare an element through let or const or var.
Implement Process:-
Step1:- Declare the array variable in the app.component.ts file
Example:- Suppose, you have an employees array that has an employee name in the app.component.ts file
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
employees:any=['John','Rom','Andrew','Mike'];
title = 'EmployeeManagement';
}
Step 2:- show the employee name in the app.component.html file through *ngFor
<h1>Employees Name</h1>
<div *ngFor="let emp_name of employees">
<div>{{emp_name}}</div>
</div>
Step 3:- Now, you show the employee names on the browser.