Skip to main content

angular - How to use for loop

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  colors = [
    'red',
    'green',
    'blue',
    'yellow',
    'orange',
    'pink'
  ];
}
app.component.html

<h2>Angular For Loop</h2>

<div *ngFor="let color of colors">
    <h3>{{color}}</h3>
</div>
More Angular tutorials