How to change the parameter of activated Route on button click
Solution 1:
Your route will still remain the same if you change the value of id
, you can try and navigate using Router
to your desired id
.
You can take help of this demo
Solution 2:
Just try to navigate to the same component by just changing the id prams
export class TodoDetailsComponent implements OnInit{
todo;
id: number;
constructor(private activatedRoute: ActivatedRoute, private service: Service,
private router : Router) { }
ngOnInit() {
this.activatedRoute.paramMap.pipe(
switchMap(params => {
this.id = +params.get('id')
return this.getTodo(this.id)
})
).subscribe(todo => this.todo = todo);
}
getTodo(id) {
return this.service.getTodo(id);
}
next() {
this.id += 1;
this.router.navigate(['/todos',this.id]);
}
Hope this will work thanks - Happy coding !!