java 文本框怎么属性绑定_如何将对象属性绑定到angular2中的文本框

我是Angular的新手,我正在尝试绑定由模型对象的文本框组成的表单 . 但我收到一个错误,如“Unhandled Promise rejection:模板解析错误:无法绑定到'NgModel',因为它不是'input'的已知属性”

我在谷歌投入了大量时间,但仍存在问题

以下是我的代码 .

html:

Project Name:

Project Manager Name:

Project Manager Email ID:

app.module.ts

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

import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

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

import { HttpModule } from '@angular/http';

import {SpotCheckStatusComponent} from './spotcheckstatus.component';

@NgModule({

imports: [ BrowserModule ,FormsModule,HttpModule ],

declarations: [ AppComponent,SpotCheckStatusComponent ],

bootstrap: [ SpotCheckStatusComponent ]

})

export class AppModule { }

projectFields.ts

export class projectFields {

public PROJECT_CODE:string;

public PROJECT_NAME:string

public PROJECT_MANAGER: string;

public PROJECT_MANAGER_EMAIL_ID: string;

}

SpotCheckStatusComponent.ts

import {Component,OnInit ,OnChanges} from '@angular/core';

import {IMyDpOptions} from 'mydatepicker';

import {HttpService} from './http.service';

import { serviceLine } from './models/serviceLine';

import { projectFields } from './models/projectFields';

@Component({

selector: 'my-app',

styleUrls:['/css/home.css'],

templateUrl:'./SpotCheckStatus.html',

providers:[HttpService]

})

export class SpotCheckStatusComponent implements OnInit

{

name = 'SpotCheckStatus';

public projectFieldsdtl: projectFields[];

constructor(

private httpService: HttpService

) {}

ngOnInit(){

this.httpService.getProjectCode(serviceline).subscribe(

response=> {

this.projectFieldsdtl=response[0];

},

error=> {

console.log("ERROR: ",error);

console.log(error.json()); //gives the object object

},

() => {

console.log("Completed");

}

);

}

}

最后,projectFieldsdtl得到了如下对象:

[{

PROJECT_CODE:"9999"

PROJECT_MANAGER:"shekat"

PROJECT_MANAGER_EMAIL_ID:"teja.ravi@gmal.com"

PROJECT_NAME:"ABFL"

}]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值