How can I get the id of a task in my todo app without using ActivatedRoute method for updating functionality in angular ?
this.route.paramMap.subscribe(params => {this.id = params.get('id');})
this is the way which I'm using now
CodePudding user response:
If you don't want to use ActivatedRoute you need to store the id in a service or in the localStorage before changing page, so in the new page you can retrieve it.
CodePudding user response:
If it's because you don't want to use an observable then you could maybe use this in ngOnit if you component initilze every time there is a new product.
const id: string = route.snapshot.params.id;
If you id comes from a component and you want to share it with another component, then you can use @output
to share it to a parent component or @input
to pass it to a child component. You could also put in a service.In Angular services or most often singletons that can be shared across your app.