Angular 2数据绑定(无法读取未定义的属性'proposta_usuario') [英] Angular 2 Data Binding (cannot read property 'proposta_usuario' of undefined)

查看:62
本文介绍了Angular 2数据绑定(无法读取未定义的属性'proposta_usuario')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Angular 2上的输入绑定数据,但是遇到了一些问题.

I'm trying to bind a data from input on Angular 2 but I'm having some problems.

这是html代码:

    <input type="text" class="animated bounceIn input-proposta" 
        placeholder="Insira sua proposta" [(ngModel)]="proposta.proposta_usuario" >

<input type="button" (click)="enviaProposta(proposta)" class="botao-medio btn-aceita" value="Enviar Proposta" >

这是组件(我为"proposta"创建了一个接口,其中有两个属性:"proposta_usuario"和"proposta_cliente")

and here's the component (I have created a interface for "proposta" in which I have two properties: 'proposta_usuario' and 'proposta_cliente')

import { Component } from '@angular/core';
import {Http, Headers} from '@angular/http';
import {ActivatedRoute} from '@angular/router';
import {DisputaComponent} from '../../disputas/disputas.component';
import {DisputaService} from '../../disputas/disputas.service';
import {disputaPropostas} from './proposta.interface';

@Component({
  moduleId: module.id,
  selector: 'detalhes',
  templateUrl: `disputas-proposta.component.html`
})

export class DetalhesNegociacaoComponent  {


    disputa: DisputaComponent;
    service: DisputaService;
    route: ActivatedRoute;
    inputProposta = false;
    proposta:disputaPropostas;

    //constructor and other functions


      enviaProposta(proposta:any){
        this.inputProposta = false;
        console.log(this.proposta.proposta_usuario);
     }

我只想在console.log上显示输入的值,但出现此错误

I just want to show the value from the input on my console.log, but I'm getting this error

无法读取未定义的属性'proposta_usuario'

Cannot read property 'proposta_usuario' of undefined

预先感谢

推荐答案

您需要实例化proposta属性,

proposta :disputaPropostas = { proposta_usuario : "", proposta_cliente: "" }

希望这会有所帮助!

这篇关于Angular 2数据绑定(无法读取未定义的属性'proposta_usuario')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆