Javascript Can';t绑定到';ngModel';因为它不是';t'的已知属性;输入';,如何在9中修复?
我已经在Javascript Can';t绑定到';ngModel';因为它不是';t'的已知属性;输入';,如何在9中修复?,javascript,angular,typescript,Javascript,Angular,Typescript,我已经在app.module.ts文件中导入了FormsModule 谁能告诉我哪里出了错 错误 应用程序模块.ts import { FormsModule } from '@angular/forms'; .... imports: [ .... FormsModule, .... ] import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from
app.module.ts
文件中导入了FormsModule
谁能告诉我哪里出了错
错误
应用程序模块.ts
import { FormsModule } from '@angular/forms';
....
imports: [
....
FormsModule,
....
]
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 {
}
}
关于.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>
我遇到过这样的问题,构建没有获取新的导入。可能尝试重新编译?在app.module.ts中导入ReactiveFormsModule如果此About组件是某个嵌套模块的一部分,则在嵌套模块文件中包含FormsModule
将其包含在app.module.ts中将不起作用 AboutComponent是否在app.module.ts中声明?@Jesse是的,它在app.module.ts文件中声明。我可能错了,但我认为当您在。。。对不起,我希望能多帮点忙。我主要使用反应式表单。确保在
NgModule
的装饰下导入FormsModule
。这是我的下一个想法。“我也遇到过这种情况。”杰西,我输入错了。实际上,我在我的项目中有两个组件名为About
。这就是为什么我要面对这个错误啊,我以前也这么做过。找到这一点做得很好。@Don G正如我在重新编译后了解到的,问题出在哪里,我可以接受你的答案,但你能否也提到我在上述评论中分享的原因?就我的经验而言,我已经看到很多次我导入了一个新的包或组件,但有些东西出现了问题。我所有的代码都很好。关闭并重新构建整个项目通常会修复它。有点像“关掉再打开”。这回答了你的问题吗?