Javascript ngSwitchCase无提供者
我在看turtorial,并试图做我学到的事情。我在下面遇到了一个错误。我不明白为什么我的浏览器控制台上会出现这个错误消息。它说Javascript ngSwitchCase无提供者,javascript,html,css,angular,Javascript,Html,Css,Angular,我在看turtorial,并试图做我学到的事情。我在下面遇到了一个错误。我不明白为什么我的浏览器控制台上会出现这个错误消息。它说[error->],但我不知道为什么它说ngSwitchCase是错误的。检查了所有文件和代码,但似乎没有问题。我的错误在哪里 错误 Uncaught Error: Template parse errors: No provider for NgSwitch (" <td>{{item.description}}</td>
[error->]
,但我不知道为什么它说ngSwitchCase是错误的。检查了所有文件和代码,但似乎没有问题。我的错误在哪里
错误
Uncaught Error: Template parse errors:
No provider for NgSwitch (" <td>{{item.description}}</td>
<td [ngSwitch]="item.action"></td>
[ERROR ->]<span *ngSwitchCase="true">
Yes
</span>
"): ng:///AppModule/AppComponent.html@25:14
No provider for NgSwitch ("
Yes
</span>
[ERROR ->]<span *ngSwitchCase="false">
No
</span>
"):
Model.ts
export class AppComponent {
items:Model[]= [
new Model('Breakfast',false),
new Model('Sport',false),
new Model('Studying',true),
new Model('Cemo',false),
]
}
export class Model
{
description:string;
action:Boolean;
constructor(description:string,action:Boolean)
{
this.description=description;
this.action=action;
}
}
您应该像这样将span包装在td标记内,因为ngSwitch指令是td元素的作用域,而不是td元素的外部
<td [ngSwitch]="item.action">
<span *ngSwitchCase="true">
Yes
</span>
<span *ngSwitchCase="false">
No
</span>
</td>
对
不
如果您只需要在两个备选方案中选择一个,您也可以使用*ngIf-else:
试着这样做:[ngSwitch]=“{{item.action}}”@ShivaniPatel我做了,但没有成功
<td [ngSwitch]="item.action">
<span *ngSwitchCase="true">
Yes
</span>
<span *ngSwitchCase="false">
No
</span>
</td>