英文:
Angular, data is shown in the console but not in the App
问题
I see you've provided some code that you're working on. If you need assistance with a specific issue or have a question about your code, please let me know, and I'll do my best to help.
英文:
So I am fetching data from the backend and it works since I can see it in the console
But as you can see, it recognizes that the data is here but it's like there's some problem with rendering. Here's the relevant code
This is HTML part of the component
<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>
And this is 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);
}
);
}
}
I tried add ngif, so that it looks like this
<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>
But still no luck
答案1
得分: 2
你的 predmet
对象有 name
和 numberOfECTS
键,而不是你正在尝试访问的 naziv
和 ects
。
英文:
Your predmet
object has name
and numberOfECTS
keyes, and not naziv
and ects
that you're trying to access.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论