简体   繁体   English

无法绑定到“ngModel”,因为它不是“输入”的已知属性,如何在 angular 9 中修复?

[英]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?谁能告诉我我在哪里做错了?

Error错误在此处输入图像描述

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.

相关问题 无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Can't bind to 'ngModel' since it isn't a known property of 'input' 无法绑定到((ngModel),因为在角度单位测试用例中它不是&#39;input&#39;的已知属性 - Can't bind to '(ngModel' since it isn't a known property of 'input' in angular unit test case 错误:无法绑定到“ ngModel”,因为它不是的已知属性 - Error: Can't bind to 'ngModel' since it isn't a known property of Angular 7:无法绑定到“元素”,因为它不是 - Angular 7 : Can't bind to 'element' since it isn't a known property of 无法绑定到“”,因为它不是“ angular 2”的已知属性 - can't bind to '' since it isn't a known property of '' angular 2 无法绑定到“ ngModel”,因为它不是“ input”的已知属性。 (“ =” col-md-4控制标签“为=” idNome“&gt; Nome: - Can't bind to 'ngModel' since it isn't a known property of 'input'. (“=”col-md-4 control-label“ for=”idNome">Nome: </label> 无法绑定到“ ngModule”,因为它不是“ input”的已知属性。 在angular 2 asp.net核心中 - Can't bind to 'ngModule' since it isn't a known property of 'input'. in angular 2 asp.net core Ant - 无法绑定到“ngModel”,因为它不是“nz-switch”的已知属性 - Ant - Can't bind to 'ngModel' since it isn't a known property of 'nz-switch' “无法绑定到&#39;ngModel&#39;,因为它不是&#39;p-calendar&#39;的已知属性”错误消息试图使用PrimeNG组件,为什么? - “Can't bind to 'ngModel' since it isn't a known property of 'p-calendar'” error message trying to use PrimeNG component, why? 带有 Angular 的 NG2 图表:无法绑定到“颜色”,因为它不是 Angular 中“画布”的已知属性 13 - NG2 Chart with Angular: Can't bind to 'colors' since it isn't a known property of 'canvas' in Angular 13
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM