AsyncPipe example

@Component({ ... })
export class TestingComponent implements OnInit {
  units: any;
  constructor(private restService:RestService) { }
  ngOnInit() {
    this.units = this.restService.getUnits();
  }
}

Template

<ng-template #loading>Loading...</ng-template>
<div *ngIf="units|async as units; else loading">
	<span *ngFor="let unit of units">
		{{unit|json}}
	</span>	
</div>

Leave a Reply