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

I have imported FormsModule in app.module.ts file.

谁能告诉我我在哪里犯错了?

Error enter image description here

app.module.ts

import { FormsModule } from '@angular/forms';

....

imports: [
   ....
    FormsModule,
   ....
 ]

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>

关于组件

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 {

    }

}
评论
ab_non
ab_non

我遇到这样的问题,即构建无法选择新的导入。愚蠢的问题,但您尝试过重新编译吗?

点赞
评论