NgSwitch - 表现出乎意料,“没有 NgSwitch 的提供者” - 异常获取

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

这是我的 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>

当我使用上面的方法实现 switchCase 时,出现如下错误:

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

同上。在我使用 ngswich 之前,它运行良好。我也已经导入了公共模块..

有人帮我解决这个问题吗?

您不能在 <ng-template> 上使用 [ngSwitch]。您可以在 HTML 元素或 <ng-container>.

上使用它