Skip to content

Instantly share code, notes, and snippets.

@natmegs
Created January 8, 2018 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natmegs/11d06af1ad6f85960eb608ed03c3ea5a to your computer and use it in GitHub Desktop.
Save natmegs/11d06af1ad6f85960eb608ed03c3ea5a to your computer and use it in GitHub Desktop.
Using <ng-template>
<ng-template>
You will never see me :(
</ng-template>
<ng-template *ngIf="showContents">
You still won’t see me (even though I’m using a structural directive, there’s nothing that's telling Angular to use me)
</ng-template>
<ng-template *ngFor="let item of items">
No dice (same reason as *ngIf above)
</ng-template>
<div *ngIf="!showTemplate else template">
Hello
</div>
<ng-template #template>
Finally I am seen! (When showTemplate is true)
</ng-template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment