Search code examples
angulartypescriptangular-ng-if

Angular 4 *ngIf in template


in template I have a table where I want if entry .status === "applied with errors" then it should return a link (with anchor tag> otherwise just a conext. I m trying with below code but its giving me error- Template parse error.

Any help.

 <ng-container   *ngFor="let entry of Entries;let idx=index"> 
     <td *ngIf="{{entry.status == Applied with Errors}} ? 
'<a>{{ entry.status }}</a>' : '{{ entry.status }}'">

Solution

  • Your question is vague, Based on my understanding I suggest you Show an alternative template using else

    <ng-container   *ngFor="let entry of Entries;let idx=index"> 
                <td *ngIf="entry.status ==='Applied with Errors'; else elseblock"> 
           <a>{{ entry.status }}</a></td>
    
           <ng-template #elseblock>
                <td> {{entry.status}} </td>
        </ng-template>
        </ng-container>