I was trying to load a child component based on data that will retrieve by HTTP get call. I was using a service to do the HTTP call and subscribing on the component's constructor. But the ngif was calling before the data retrieve.
so i have applied async pipe in the ngif but it is triggering another error.
service code:
GetContest(id){
return this.http.get(this.baseurl+id);
}
constructor of component:
this.service.GetContest(this.route.snapshot.paramMap.get('id')).
subscribe( (res)=> {
this.contest = res;
console.log(this.contest);
});
template ngif:
<app-beforecontest *ngIf="contest.startTime<date "></app-
beforecontest>
above codes generate an error:
TypeError: Cannot read property 'startTime' of null
and after this I joined async pipe like this:
<app-beforecontest *ngIf="(contest|async).startTime<date "></app-
beforecontest>
and it is generating an error:
ContestComponent.html:1 ERROR Error: InvalidPipeArgument: '[object
Object]' for pipe 'AsyncPipe'
at invalidPipeArgumentError