无法使用jhipster项目绑定角度数据

时间:2017-08-14 10:40:11

标签: angular typescript jhipster

我已经生成了jhipster项目。 我在其中使用了几个实体ContratEntity和VoitureEntity。

我使用的是JDL STUDIO。

我的问题是我试图在contrat-dialog.component.html中添加一些修改。

作为验证,我试图在控制台中显示我的参数值,但它无法绑定数据。

  

错误类型错误:_co.contrat.voiture未定义

[contrat.component.html]

<form name="editForm" role="form" novalidate #editForm="ngForm">
...
<div class="form-group">
                    <label class="form-control-label" jhiTranslate="assistanceApp.voiture.immatriculation" for="field_immatriculation">Immatriculation</label>
                    <input type="text" class="form-control" name="immatriculation" id="field_immatriculation" [(ngModel)]="contrat.voiture.immatriculation"
                         required pattern="\d{4}TU\d+" />
</div>
<button type="button"  class="btn btn-primary" 
(click)="addVoitureToContrat()" >
                    ADD
                </button>
</form>

[contrat.component.ts]

import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Response } from '@angular/http';

import { Observable } from 'rxjs/Rx';
import { NgbActiveModal, NgbModalRef } from '@ng-bootstrap/ng-
bootstrap';

import { JhiEventManager, JhiAlertService } from 'ng-jhipster';

import { Contrat } from './contrat.model';
import { ContratPopupService } from './contrat-popup.service';
import { ContratService } from './contrat.service';
import { Voiture, VoitureService } from '../voiture';
import { Assuree, AssureeService } from '../assuree';
import { RefPack, RefPackService } from '../ref-pack';
import { RefCompagnie, RefCompagnieService } from '../ref-compagnie';
import { VoiturePopupService } from '../voiture/voiture-
popup.service';
import { ResponseWrapper } from '../../shared';
import { RefMarque, RefMarqueService } from '../ref-marque';

@Component({
selector: 'jhi-contrat-dialog',
templateUrl: './contrat-dialog.component.html',
styleUrls: [
    'contrat-dialog.css'
]
})
export class ContratDialogComponent implements OnInit {

contrat: Contrat;

addVoitureToContrat()
{
  console.log(this.contrat.voiture);
}

[contrat.model.ts]

import { BaseEntity } from './../../shared';
import {Voiture} from '../voiture'
export class Contrat implements BaseEntity {
   constructor(
    public id?: number,
    public numero?: number,
    public debut?: any,
    public fin?: any,
    public voiture?: Voiture,
    public assure?: BaseEntity,
    public pack?: BaseEntity,
    public compagnie?: BaseEntity,
   ) {
   }
}

[voiture.model.ts]

  import { BaseEntity } from './../../shared';
  export class Voiture implements BaseEntity {
  constructor(
    public id?: number,
    public immatriculation?: string,
    public miseCirculation?: any,
    public puissanceFiscale?: number,
    public marque?: BaseEntity,
    public contrat?: BaseEntity,
   ) {
   }

}

我希望一切都清楚。

0 个答案:

没有答案