Angular 8 *ngFor Directive
The *ngFor directive is used to repeat a portion of HTML template once per each item from an iterable list (Collection). The ngFor is an Angular structural directive and is similar to ngRepeat in AngularJS. Some local variables like Index, First, Last, odd and even are exported by *ngFor directive.
Syntax of ngFor
See the simplified syntax for the ngFor directive:
How to use ngFor Directive?
To Use ngFor directive, you have to create a block of HTML elements, which can display a single item of the items collection. After that you can use the ngFor directive to tell angular to repeat that block of HTML elements for each item in the list.
Example for *ngFor Directive
First, you have to create an angular Application. After that open the app.component.ts and add the following code.
The following Code contains a list of Top 3 movies in a movies array. Let's build a template to display these movies in a tabular form.
Now, open the app. component.html and add the following code:
When you run the application, It will show the movies in tabular form.