Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NgSwitch - behaves unexpected , `No provider for NgSwitch` - exception getting

here is my html:

<ng-container *ngIf="col.data !== ''">
    <ng-template [ngSwitch]="col.data">
        <ng-container *ngSwitchCase="'Page'">
            <div>{{getData(data, col.data, col.dataName)}}</div>
        </ng-container>
        <ng-container *ngSwitchDefault>
            {{getData(data, col.data, col.dataName)}}
        </ng-container>
    </ng-template>
</ng-container>

when i implement the switchCase using above, getting an error as:

No provider for NgSwitch ("<ng-template [ngSwitch]="col.data"> [ERROR ->]<ng-container *ngSwitchCase="'Page'">

like above. until i use the ngswich it was worked well. I have already imported common module too..

any one help me to sort this issue?

like image 868
3gwebtrain Avatar asked Aug 22 '19 16:08

3gwebtrain


1 Answers

You cannot use [ngSwitch] on <ng-template>. You can either use it on HTML elements, or <ng-container>.

like image 73
Tomasz Kula Avatar answered Sep 27 '22 21:09

Tomasz Kula