So I am fetching data from the backend and it works since I can see it in the console enter image description here

但正如您所看到的,它识别出数据在这里,但它似乎在渲染方面存在一些问题.以下是相关代码

这是组件的HTML部分

<h4>Details for Student: {{newStudent?.jmbag}}</h4>
<hr>
<span>JMBAG: </span>{{newStudent?.jmbag}}<br>
<span>ECTS: </span>{{newStudent?.ects}}
<div *ngIf="student?.pay">Tuition should be paid.</div>
<hr>
<div class="row">
  <div *ngFor="let predmet of predmeti">
    <div>
      <a routerLink="/detailsPredmeti/{{newStudent?.jmbag}}">
        <span>{{predmet.naziv}} </span>
        <span>{{predmet.ects}} </span>
      </a>
      <span> - </span>
    </div>
  </div>
</div>
<hr>
<a routerLink="/students"><h5>Povratak</h5></a>

这是TS

import { Component, OnInit } from '@angular/core';
import { Student } from '../student';
import { StudentService } from '../student.service';
import { StudentDTO } from '../studentDTO';
import {PredmetiService} from "../predmeti.service";
import { ActivatedRoute } from '@angular/router';
import { Predmet } from '../predmet';

@Component({
  selector: 'app-student-predmeti',
  templateUrl: './student-predmeti.component.html',
  styleUrls: ['./student-predmeti.component.css']
})
export class StudentPredmetiComponent implements OnInit {

  student: Student;
  newStudent: StudentDTO;
  predmeti: Predmet[];
  constructor(
    private studentService: StudentService,

    private predmetiService: PredmetiService,
    private route: ActivatedRoute
  ) { }

  ngOnInit(): void {
    this.route.paramMap.subscribe(() => {
      this.handleStudentDetails();
    })
  }

  handleStudentDetails() {
    const theStudentJmbag: string = this.route.snapshot.paramMap.get('jmbag')!;

    this.studentService.getStudentByJmbag(theStudentJmbag).subscribe(
      data => {
        this.newStudent = data;
        console.log('Student:', this.newStudent);
      }
    );

    this.predmetiService.getCoursesByStudentJmbag(theStudentJmbag).subscribe(
      data => {
        this.predmeti = data;
        console.log('Predmeti:', this.predmeti);
      }
    );
  }



}

我try 添加ngif,使其如下所示

<h4>Details for Student: {{newStudent?.jmbag}}</h4>
<hr>
<span>JMBAG: </span>{{newStudent?.jmbag}}<br>
<span>ECTS: </span>{{newStudent?.ects}}
<div *ngIf="student?.pay">Tuition should be paid.</div>
<hr>
<h5>Predmeti:</h5>
<div class="row">
  <table *ngIf="predmeti">
    <thead>
      <tr>
        <th>Naziv</th>
        <th>ECTS</th>
      </tr>
    </thead>
    <tbody>
      <tr *ngFor="let predmet of predmeti">
        <td>{{ predmet.naziv }}</td>
        <td>{{ predmet.ects }}</td>
      </tr>
    </tbody>
  </table>
</div>
<hr>
<a routerLink="/students"><h5>Povratak</h5></a>

但还是没有运气

推荐答案

您的predmet对象具有namenumberOfECTS Kye,而不是您试图访问的nazivects.

Angular相关问答推荐

自动完成搜索过滤器不适用于Angular 中动态添加的输入字段

带输入的单位测试Angular 分量.需要

笔刷Angular 为17

在Angular 17独立模式下,如何使用Swiper 11.0.5版使Bootstrap下拉菜单在Swiper元素外部可见

我应该对我想要在我的Angular 17+组件中显示的任何变量使用信号吗?

使用 Angular 类构造函数来获取依赖项

NGX-Translate如何不得到404?

从具有特定 node 值的现有数组创建新数组

Angular 15:在范围内提供相同标记时附加到提供的值

将 autoSpy 与 ng-mocks 一起使用时,如何重置 jasmine 间谍调用?

正确理解 angular14 中的注入 - 必须从注入上下文中调用注入()

*ngIf 和 *ngFor 在 元素上使用

找不到模块'webpack'

Angular 2 - 事件列表

请添加@Pipe/@Directive/@Component 注解

在Angular2的 Select 列表中设置最初 Select 的项目

Angular 2 组件不是任何 NgModule 的一部分

在 Angular 2 中使用 store (ngrx) 有什么好处

RxJS:takeUntil() Angular 组件的 ngOnDestroy()

ngIf - 判断后表达式已更改