Skip to content

Angular, Directive *ngFor

2017-11-13 04:00:26

Simple example of ngFor directive that is part of Angular core. Everything what you need will be generated after executing this command ng new hello-word. After that, what you have to do, is adjust few files. Of course more you can find in Angular documentation, here we have only my notes. One more thing, if you don't like to install node mess on your local computer you can use my or similar docker image


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

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
export class AppComponent {
  title = 'app';

  computers = [
    {id: 1, name: 'com_ms_001'},
    {id: 2, name: 'com_ms_002'},
    {id: 3, name: 'com_ms_003'},
    {id: 4, name: 'com_ms_004'},
    {id: 5, name: 'com_ms_005'}


<ul><li *ngfor='"let' as="" com="" computers;="" even="" even;="" first="" first;="" index="" index;="" last="" last&quot;="" odd="" odd;="" of="">
    {{ index }} / {{ }}
    <span *ngif='"even"'>even</span>
<span *ngif='"odd"'>odd</span>
<span *ngif='"first"'>first</span>
<span *ngif='"last"'>last</span>