NgSwitch - behaves unexpected , `No provider for NgSwitch` - exception getting
Asked Answered
I

2

8

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 switch case as I did in the code above, I get this error:

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

Like I said, Until I use the ngSwitch, it was working properly. I have already imported the common module too...

Can anyone help me sort out this issue?

Intinction answered 22/8, 2019 at 16:27 Comment(0)
A
13

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

Armand answered 22/8, 2019 at 16:45 Comment(0)
S
0

I got a similar No provider for NgSwitch parse error. For me, the cause of the problem was that I was using NgSwitch like *ngSwitch="..." (wrong) instead of [ngSwitch]="..." (correct). I hope this helps somebody :)

Seventh answered 25/5, 2023 at 17:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.