The ng-template directive and ngIf

The ng-template directive allows us to run a set of HTML tag block based on ngIf|else condition. TemplateRef is the class name and <ng-template> is the html tag — they are both referencing the same thing.

We can use <ng-template> with ngFor, ngIf and ngSwitch. Using TemplateRef and ViewContainerRef we can reuse the code of
<ng-template> in our HTML template. <ng-template> example with ngFor is as follows.

<ng-template ngFor let-person [ngForOf]= "allPersons" let-i="index">
<p>{{i + 1}}. {{}} : {{person.age}} </p>

In Angular allow us to use ng-template with if/else scenario below example.

       <div *ngIf="photoID; then govId else newGovId" class="govID"></div>
        <ng-template #govId>
            <h2>Government Identity Card </h2>
              <img src={{photoID}}>
            <div class="gov-id">
              <label for="file">Edit Government ID</label>
              <input type="file" class="custom-file-input" (change)="detectGovtIdFile($event)">
        <ng-template #newGovId>
            <input type="file" class="custom-file-input" (change)="detectGovetIdFile($event)">

A simpler version of ngIf and else template

We can used platform variable of Platform services directly into template. To check if plaftform is android or not.
<div ngIf= "'android'); then truecondition else falseCondition">
<div *ngIf="searchResults;  else elseBlock">

</div> // End of true Condition
<ng-template #elseBlock>