1

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.

1
  • Thanks guys. I lately found out I was adding this function inside a different component with similar name. Just remind me again some little detail could fuck me good time...... Commented Aug 1, 2019 at 5:55

3 Answers 3

1

You are populating this.courseInfo while you are using courseDetail on the template which is a @input to the component. So either you use this.courseInfo or set data in courseDetail which is then given to your component as @input.

Sign up to request clarification or add additional context in comments.

3 Comments

I have remove the @input and only use the courseInfo in the component, but the problem still remain. It is not displayed on the page?
Would it be cache problem?
I dont think its a cache issue. moreover you can try assigning the initially courseInfo as null and add a *ngIf on parent div for courseInfo to be not null this should work
0

I think it should be:

<div class="intro-title">
   <h2> {{ courseInfo?.courseTitle }} </h2>
</div>

Comments

0

I think the courseDetail input is undefined. You should try using courseInfo?.courseTitle instead.

1 Comment

sorry that was a mis-type in the question. I have correct my question but the problem is still remain.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.