I am running into problem with display my data on page after a post request to my API. I have never ran into this problem before and I have no idea what causes it.This is just some easiest implementation but it just not working.
My Service:
getCourseInfo(data): Observable<any> {
const id = parseInt(data);
const url = `${this.baseUrl}/TblUnimeCourses/getCourseInfo/` + id;
return this.http.get(url);
}
My resolver for the page:
constructor(private courseService: CourseService) {}
resolve(route: ActivatedRouteSnapshot) {
return this.courseService.getCourseInfo(route.paramMap.get("id"));
}
My Component:
export class IntroComponent implements OnInit {
courseInfo: CourseInfo;
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.courseInfo = this.route.snapshot.data.data;
console.log(this.courseInfo);
}
}
export interface CourseInfo {
courseTitle: any;
coursePrice: number;
}
My console log:
courseCode: "IT101"
coursePrice: 300
courseTitle: "Information Technology"
description: "Monash University Foundation Course"
introduction: "Introductory course"
My template: ( sorry I pasted wrong code here while i was trying other approach, then I double checked my own code, it is using courseInfo this object for display. so the problem is still not fixed yet. Also the question mark I added after this object doesn't solve this problem.)
<div class="intro-title">
<h2>{{ courseInfo?.courseTitle }}</h2>
</div>
However, the courseTitle is never displayed even I have got my data back and I have console log it I can see them in the development tool.