Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between this.route.params and this.route.snapshot.params in angular ActivatedRoute

Tags:

angular

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

like image 682
kichu Avatar asked Oct 17 '25 11:10

kichu


1 Answers

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

like image 183
prograk Avatar answered Oct 20 '25 02:10

prograk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!