In angular 2 document, * and template, we know that the *ngIf, *ngSwitch, *ngFor can be expanded to ng-template tag. My question is:
I think the ngIf
or ngFor
without *
can also be translated and expanded to template tag by angular engine.
The following code
<hero-detail *ngIf="currentHero" [hero]="currentHero"></hero-detail>
would be the same as
<ng-template [ngIf]="currentHero">
<hero-detail [hero]="currentHero"></hero-detail>
</ng-template>
So why bother designing a strange symbol asterisk(*
) in angular 2?
<template>
tags because the*
prefix syntax allowed us to skip those tags and focus directly on the HTML element that we are including, excluding, or repeating. – Tushar