constructor(private recipeService : RecipeService , private route : ActivatedRoute) { }
ngOnInit() {
const id = this.route.params['id'];
const id = this.route.snapshot.params['id'];
}
what is the difference between route.snapshot.params and route.params in angular when should we use route.snapshot.params and when should we use route.params
As its mentioned on official angular website.
Snapshot: You get the current snapshot of this route at a particular moment in time. (Contains the information about a route associated with a component loaded in an outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to traverse the router state tree.) You can check description with example in the following link. https://angular.io/api/router/ActivatedRouteSnapshot#description
params: Is A Observable and you can subscribe to it. (An observable of the matrix parameters scoped to this route.) You can check description with example in the following link https://angular.io/api/router/ActivatedRoute#description
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With