Answer the question
In order to leave comments, you need to log in
How to get a dynamic route parameter in a service?
Angular 2
You can receive in a component and pass it to service methods, which is not very convenient.
In the component:
create() {
this.route.paramMap.subscribe((params) => {
this.service.cerate(params.get('id'));
});
}
update() {
this.route.paramMap.subscribe((params) => {
this.service.update(params.get('id'));
});
}
service: any;
ngOnInit(): void {
this.route.paramMap.subscribe((params) => {
this.service = this.seviceProvider.factory(params.get('id'));
}
}
create() {
this.service.cerate();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question