这个问题是因为在使用Angular的指令时,需要先在模块中导入对应的模块(如FormsModule、CommonModule等),以便让Angular识别这些指令。在这种情况下,需要在模块中导入CommonModule,以便Angular认识ngClass、ngStyle、ngSwitch等指令。
示例代码:
import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core';
@NgModule({ imports: [ CommonModule ], declarations: [ MyComponent ] }) export class MyModule { }
@Component({ selector: 'my-component', template: '
' }) export class MyComponent { }