Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ngSwitchCase无提供者_Javascript_Html_Css_Angular - Fatal编程技术网

Javascript ngSwitchCase无提供者

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>

我在看turtorial,并试图做我学到的事情。我在下面遇到了一个错误。我不明白为什么我的浏览器控制台上会出现这个错误消息。它说
[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>