I'm using Ant Design for Angular (ng-zorro-antd), and using the simple switch
module to display a switch.
When I add the code per the docs:
<nz-switch [ngModel]="true"></nz-switch>
The app won't pile, and I get this error:
Can't bind to 'ngModel' since it isn't a known property of 'nz-switch'
I'm using Ant Design for Angular (ng-zorro-antd), and using the simple switch
module to display a switch.
When I add the code per the docs:
<nz-switch [ngModel]="true"></nz-switch>
The app won't pile, and I get this error:
Can't bind to 'ngModel' since it isn't a known property of 'nz-switch'
- try to import FormsModule into a module where declared this ponent – Yan Koshelev Commented May 23, 2022 at 7:19
- You either forgot to import FormsModule in the parent module, or forgot to import the ponent(where you are using nz-switch) inside the module where nz-switch module is placed. – Muhammad Umar Commented May 23, 2022 at 8:58
- Yes, thanks, that was it. The issue was that I was importing the FormsModule in a different "shared" module file. Once I moved it directly into the module where the switch is used I was good. – Tony Brasunas Commented May 23, 2022 at 19:26
1 Answer
Reset to default 4Import FormsModule
in the right module
While it doesn't say it in the documentation, you need to have Angular's FormsModule
imported in order for the ngModel
binding to work.
If you have an app with just one module, this is easy. Simply import the FormsModule
as below in your one and only xxx.module.ts
file.
If you're working on an app with multiple modules, you have to ensure you're importing it in the module where you're going to use the nz-switch
In that module, where you're using the nz-switch
, in the xxx.module.ts
file:
import { FormsModule } from '@angular/forms`;
...
@NgModule({
declaration: [ ... ],
imports: [
...,
FormsModule
],
...
You should be good to go.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744955074a4603145.html
评论列表(0条)