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 compile, and I get this error:
Can't bind to 'ngModel' since it isn't a known property of 'nz-switch'
Import 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, as I was, 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.