本文介绍了无法绑定到“ng-model",因为它不是“input"的已知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始学习 Angular 2,对于这个错误尝试了堆栈溢出中的几乎所有链接,但仍然,请帮助我理解为什么即使导入后仍然产生错误 FormsModule

Start learning Angular 2 , for this error tried almost all links in stack-overflow but still , please help me understand why still produces error even after import FormsModule

这是我的 customer.ts 文件

This is my customer.ts file

export class Customer {

  public CustomerName: string = "asdsad";
  public Code: string = "asdsa";
  public Amount: string = "asdasd";
}

app.component.ts

app.component.ts

import { Component } from '@angular/core';

import { Customer } from "./Customer"

@Component({
selector: 'my-app',
moduleId: module.id,
templateUrl: './st.html'
})

   export class AppComponent {
customerobj: Customer = new Customer();
   }

app.module.ts

app.module.ts

            import { NgModule } from "@angular/core"
            import { BrowserModule } from "@angular/platform-browser"
            import { FormsModule } from '@angular/forms';
            import { AppComponent } from "./app.component"
            @NgModule({
                imports: [BrowserModule, FormsModule ],
                declarations: [AppComponent],
                bootstrap: [AppComponent]
            })

            export class AppModule { }

main.ts

    import { platformBrowserDynamic } from "@angular/platform-browser-dynamic"

    import { AppModule } from "./app.module"

    platformBrowserDynamic().bootstrapModule(AppModule);

推荐答案

对于 Angular2/4 使用 ngModel

ng-model 用于角度 1

ngModel 用于 angular 2

ngModel is For angular 2

这篇关于无法绑定到“ng-model",因为它不是“input"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:48