如何创建和更新在Angular项目(由JHipster生成)中合成的实体?

时间:2019-01-30 10:20:36

标签: angular typescript jhipster

我正在尝试使用JHipster重新创建Spring Petclinic项目。兽医和主人都是人。我想删除网站中的“人员”页面,然后修改“创建和编辑“兽医和所有者”页面,以使“人员”类中的字段( firstName lastName )也可以创建和更新。

enter image description here

要重新创建问题,请创建一个新的JHipster项目。这是我的.yo-rc.json。使用

创建实体和关系
jhipster import-jdl petclinic.jdl

petclinic.jdl

这里是对owner-update.component.html页所做的更改的链接,并试图将 personService 拉入owner-update.component.ts中的save方法的第66-88行。

save() {
    this.isSaving = true;
    if (this.owner.id !== undefined) {
        this.subscribeToSaveResponsePerson(this.personService.update(this.owner.person));
        this.subscribeToSaveResponse(this.ownerService.update(this.owner));
    } else {
      if(this.owner.person.id === undefined){
        this.person.firstName = this.owner.person.firstName;
        this.person.lastName = this.owner.person.lastName;
        this.subscribeToSaveResponsePerson(this.personService.create(this.person));
      }
        this.owner.person = this.person;
        this.subscribeToSaveResponse(this.ownerService.create(this.owner));
    }
}

protected subscribeToSaveResponse(result: Observable<HttpResponse<IOwner>>) {
    result.subscribe((res: HttpResponse<IOwner>) => this.onSaveSuccess(), (res: HttpErrorResponse) => this.onSaveError());
}

protected subscribeToSaveResponsePerson(result: Observable<HttpResponse<IPerson>>) {
  result.subscribe((res: HttpResponse<IPerson>) => this.onSaveSuccess(), (res: HttpErrorResponse) => this.onSaveError());

}

使用上述方法,确实可以保存更新,但是页面导航异常。尝试创建一个全新的所有者(当已经没有人的时候)根本行不通,但是应该可以帮助解释我要做什么。

我该如何解决这个问题?我知道我可以删除Person对象,并像此github example一样在所有者和兽医中都包含字段 firstName lastName ,但是我会希望能够应用该原理。

0 个答案:

没有答案