angular - 无法获取实体

标签 angular angular6

我有这两门课:

学生***1地址

export class Student
{
    id: number;
    firstName: string;
    adresse: Adresse;
}

export class Adresse
{
    id: number;
    email: string;
    phone: string;
    town: string;
    city: string;
}

我从list-student.component.ts中选择一个学生

<table class="table">
      <thead>
        <tr>
          <th>Id</th>
          <th>Name</th>
          <th>Update</th>
        </tr>
      </thead>
      <tbody *ngIf="!loader">
        <tr *ngFor="let student of userbs | async" style="width: 1500px;">
          <td>{{student.id}}</td>
          <td>{{student.name}}</td>
          <td><span class="button is-small btn-warning" (click)='editUser(student)'>Update</span></td>
        </tr>
      </tbody>
    </table>

并且函数 editUsermodify-student.component.ts 中定义,如下所示:

 editUser(student: Student): void
    {
        console.log("--------------Student's adress: " + -->  It gives the error.
        console.log("--------------Student's name: " + student.name);  -->  It gives the expected name for Example AJT_82 or Adrita.

        this.router.navigate(['modify-student']);
    };

我在尝试在 console.log 上恢复学生的电子邮件时遇到此错误。

ERROR TypeError: "student.adresse is undefined"

This is the console

感谢@AJT_82 先生和@Adrita 女士,我知道了问题的原因。 出现此错误是由于使用后端(Spring Boot)的休息服务。我添加注释

@JsonIgnore 
private Adresse adresse; 

这就是为什么在 postman 上,我无法显示学生内部的地址对象。 这就是为什么我因 @JsonIgnore 导致地址未定义。 但这会导致 Spring Boot 上的另一个异常,因为消除了 @JsonIgnore ,即

com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25) ~[jackson-databind-2.9.6.jar:2.9.6].

您对解决这个问题有什么想法吗? 非常感谢。

最佳答案

请确保Student和Adresse的映射是单向的。 HTH。

关于angular - 无法获取实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56702052/

相关文章:

angular - 如何更改 Angular Material select 中的滚动条样式?

javascript - jQuery scrollTo 仅在 Chrome 61 之后有效

javascript - 使用 observable 和订阅进行工作

angular - 比较Angular 6中的两个日期

spring - 找不到可接受的文件下载表示

node.js - npm 找不到 js 文件

javascript - @Input 在 ngOnInit Angular 2 上未定义

javascript - 在 Angular 6 中使用 toPromise 的正确方法

node.js - nodejs fatal error : CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

angular - 如何在 Angular 6 中将 ag-grid 从版本 18.1.0 更新到 20.1.0?