Hi sir, i have one doubt in this lecture as you said that ngOnInit gets called once whenever component gets load right? but as in previous button and next button we are adding and subtracting the id that means somewhere we are changing the route and as we change the route it should go to routes and load the course-detail component again and as it loads it should execute the ngOnInit once again. so why we have to use subscribe. Please explain me as this, as i having this as a doubt.
Hi Sir, From this session I understood that paramMap or params observable is used instead of snapshot as these observables emit new value when a route parameter gets changed. I am confused as we are using these observables in ngOnInit hook as I am assuming ngOnInit hook gets called only once, how come the observables in ngOnInit are updated whenever route parameter is changed.
Hi there. Let me try to explain in a simple way. We need to subscribe to an observable only once. And that we are doing in ngOnInt. As you rightly said, ngOnInit will be called only once and at that time we are subscribing to the param or paramMap observable. Now everytime the observable will emit a new value, since we have subscribed to it, the next callback function passed to subscribe method will be called. Remember that ngOnInit is not getting executed again. It's the next callback function which is getting called, whenever the observable emits a new value. I hope i have cleared your doubt. If you still have questions, please watch observable related lectures from this playlist.
hi sir, here what is the meaning of initialisation, i mean in courses page, when we click details of one course it will render that particular course detail and when we come back and if we click on other course details it will render that particular course. but this is not case with previous and next. so my doubt is in course page also we initialised for first course detail, when we come back and click on next course details it should not show the next one. but how it is showing.
PrevCourseButtonClicked(){ this.selectedId--; this.router.navigate(['Courses','Course',this.selectedId]); } NextCourseButtonClicked(){ this.selectedId++; this.router.navigate(['Courses','Course',this.selectedId]); } why this is not working?
what a great practical use case of an observable . Thank u !!!!!!!!!!!
Thank you sir!
Hi sir, i have one doubt in this lecture as you said that ngOnInit gets called once whenever component gets load right? but as in previous button and next button we are adding and subtracting the id that means somewhere we are changing the route and as we change the route it should go to routes and load the course-detail component again and as it loads it should execute the ngOnInit once again. so why we have to use subscribe.
Please explain me as this, as i having this as a doubt.
Hi Sir, From this session I understood that paramMap or params observable is used instead of snapshot as these observables emit new value when a route parameter gets changed. I am confused as we are using these observables in ngOnInit hook as I am assuming ngOnInit hook gets called only once, how come the observables in ngOnInit are updated whenever route parameter is changed.
Hi there. Let me try to explain in a simple way. We need to subscribe to an observable only once. And that we are doing in ngOnInt. As you rightly said, ngOnInit will be called only once and at that time we are subscribing to the param or paramMap observable.
Now everytime the observable will emit a new value, since we have subscribed to it, the next callback function passed to subscribe method will be called.
Remember that ngOnInit is not getting executed again. It's the next callback function which is getting called, whenever the observable emits a new value. I hope i have cleared your doubt.
If you still have questions, please watch observable related lectures from this playlist.
@@procademy Thank you very much for the detailed explanation sir.
@@procademy Thank You Sir! I was also confused in this scenario.
hi sir, here what is the meaning of initialisation, i mean in courses page, when we click details of one course it will render that particular course detail and when we come back and if we click on other course details it will render that particular course. but this is not case with previous and next. so my doubt is in course page also we initialised for first course detail, when we come back and click on next course details it should not show the next one. but how it is showing.
Sir also make a videos of Angular Universal, Ssr, lazy loading, Angular 17 new features in this tutorial series
so Josef Stalin is your student
PrevCourseButtonClicked(){
this.selectedId--;
this.router.navigate(['Courses','Course',this.selectedId]);
}
NextCourseButtonClicked(){
this.selectedId++;
this.router.navigate(['Courses','Course',this.selectedId]);
}
why this is not working?
Thank you sir!