为了解决这个问题,需要在模块中导入 CommonModule 和 FormsModule。 在你的模块中,添加以下代码:
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
CommonModule,
FormsModule
],
declarations: [
YourComponent
]
})
export class YourModule { }
确保你的组件在 declarations 数组中声明。 接下来,我们需要切换到使用 ngClass 绑定语法。 可以这样做:
或者更简洁的方式:
这应该能够解决异常并让你的代码正常运行。
上一篇:Angular9异步等待(async-await)出现未捕获的(inpromise)错误。
下一篇:Angular9中出现了NULLINJECTORERROR:NOPROVIDERFORNGXSMARTMODALSERVICE的错误。