Angular8使用Ant Design Mobile 的List 提示 Can’t bind to ‘ngModel’ since it isn’t a known property of ‘ListItem’,具体错误如下:
core.js:6014 ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'ngModel' since it isn't a known property of 'ListItem'. ("
[arrow]="'horizontal'"
[mode]="'date'"
[ERROR ->][(ngModel)]="value"
(onOk)="onOk($event)"
>
"): ng:///KeepbookModule/IndexComponent.html@55:16
Error: Template parse errors:
Can't bind to 'ngModel' since it isn't a known property of 'ListItem'. ("
[arrow]="'horizontal'"
[mode]="'date'"
[ERROR ->][(ngModel)]="value"
(onOk)="onOk($event)"
>
"): ng:///KeepbookModule/IndexComponent.html@55:16
at syntaxError (compiler.js:2175)
at TemplateParser.parse (compiler.js:11388)
at JitCompiler._parseTemplate (compiler.js:25963)
at JitCompiler._compileTemplate (compiler.js:25951)
at compiler.js:25895
at Set.forEach (<anonymous>)
at JitCompiler._compileComponents (compiler.js:25895)
at compiler.js:25808
at Object.then (compiler.js:2166)
at JitCompiler._compileModuleAndComponents (compiler.js:25807)
at resolvePromise (zone-evergreen.js:797)
at resolvePromise (zone-evergreen.js:754)
at zone-evergreen.js:858
at ZoneDelegate.invokeTask (zone-evergreen.js:391)
at Object.onInvokeTask (core.js:39680)
at ZoneDelegate.invokeTask (zone-evergreen.js:390)
at Zone.runTask (zone-evergreen.js:168)
at drainMicroTaskQueue (zone-evergreen.js:559)
解决办法
在对应的module里面导入FormsModule
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { KeepbookRoutingModule } from './keepbook-routing.module';
import { IndexComponent } from './index/index.component';
import { NgZorroAntdMobileModule } from 'ng-zorro-antd-mobile';
import { FormsModule } from '@angular/forms';//导入此module
@NgModule({
declarations: [IndexComponent],
imports: [
CommonModule,
FormsModule,//imports
KeepbookRoutingModule,
NgZorroAntdMobileModule
]
})
export class KeepbookModule { }