[英]Ant - Can't bind to 'ngModel' since it isn't a known property of 'nz-switch'
我正在使用 Ant Design for Angular (ng-zorro-antd),並使用簡單的switch
模塊來顯示開關。
當我根據文檔添加代碼時:
<nz-switch [ngModel]="true"></nz-switch>
該應用程序無法編譯,我收到此錯誤:
Can't bind to 'ngModel' since it isn't a known property of 'nz-switch'
在正確的模塊中導入FormsModule
雖然文檔中沒有說明,但您需要導入 Angular 的FormsModule
才能使ngModel
綁定起作用。
如果您的應用程序只有一個模塊,這很容易。 只需在您唯一的xxx.module.ts
文件中導入FormsModule
,如下所示。
如果您像我一樣在開發具有多個模塊的應用程序,則必須確保將其導入要使用nz-switch
的模塊中
在您使用nz-switch
的那個模塊中,在xxx.module.ts
文件中:
import { FormsModule } from '@angular/forms`;
...
@NgModule({
declaration: [ ... ],
imports: [
...,
FormsModule
],
...
你應該很高興。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.