[英]Can't bind to 'ngModel' since it isn't a known property of 'input', how to fix in angular 9?
I have imported FormsModule
in app.module.ts
file.我在
app.module.ts
文件中导入了FormsModule
。
can anyone tell me where i did mistake?谁能告诉我我在哪里做错了?
app.module.ts app.module.ts
import { FormsModule } from '@angular/forms';
....
imports: [
....
FormsModule,
....
]
about.component.html about.component.html
<form>
<div class="form-group">
<label for="banner">Banner Image Url</label>
<input type="text"
class="form-control"
[(ngModel)]="banner.banner_image"
id="banner"
name="banner"
/>
</div>
</form>
about.component.ts about.component.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import {UserService} from '../../service/user.service';
class Banner {
id: number;
banner_image: number;
}
@Component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.css']
})
export class AboutComponent implements OnInit {
banner: Banner = new Banner();
constructor() {
}
ngOnInit(): void {
}
}
I've had problems like this where the build doesn't pick up a new import.我遇到过这样的问题,即构建没有获取新的导入。 Maybe try re compiling?
也许尝试重新编译?
Import ReactiveFormsModule in app.module.ts在 app.module.ts 中导入 ReactiveFormsModule
If this About component is a part of some nested module, then include FormsModule in nested module file.如果此About组件是某个嵌套模块的一部分,则在嵌套模块文件中包含FormsModule 。
Including it in app.module.ts will not work.将其包含在 app.module.ts 中将不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.