user16953799
user16953799

Reputation:

I need to get the id for updating a field in angular

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

Upvotes: 0

Views: 62

Answers (2)

XRaycat
XRaycat

Reputation: 1140

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.

Upvotes: 0

voidbrain
voidbrain

Reputation: 362

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.

Upvotes: 1

Related Questions