这是我要运行的代码:
<div [ngStyle]="getStartTimeStyle()" [ngSwitch]="event?.time">
Time: {{event?.time}}
<span *ngSwitchCase="'8:00 am'">(Early start)</span>
<span *ngSwitchCase="'10:00 am'">(Late Start)</span>
<span *ngSwitchDefault>(Normal Start)</span>
</div>
但它显示的错误如下:
错误 NG8002:无法绑定到“ngStyle”,因为它不是“div”的已知属性。
<div [ngStyle]="getStartTimeStyle()" [ngSwitch]="event?.time">
无法绑定到“ngSwitch”,因为它不是“div”的已知属性。
<div [ngStyle]="getStartTimeStyle()" [ngSwitch]="event?.time">
请帮忙,我该如何解决这个问题?
~~~~~~~~~~~~~~~~~~~~~~~~
答案 0 :(得分:0)
您需要在要使用“ngSwitch”和“ngStyles”指令的模块中导入“CommonModule”,因为这两个指令都是“CommonModule”的一部分。
import { CommonModule } from '@angular/common';
答案 1 :(得分:-1)
不要使用 div 使用 container_element
我给你留下了文档的链接,以便你可以更详细地查看