Angular *ngFor Directive

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 file to display the data.

Syntax:-


 *ngFor="let element of elementArray"

Note:- You can declare element through let or const or var.

Implement Process:-

Step1:- Declare array variable in the app.component.ts file

Example :- Suppose you have an employees array which has 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';

}

Step2:- 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>

Step3:- Now, you show the employee names on the browser.