I'm trying to create a service in angular 5, which will query the URL parameters, extract required parameters and assign it to specific type of interface which I created. I tried this, but it is not working:
export class UrlQueryService {
urlParams = {} as UrlQueryParams;
constructor( private router: Router, private route: ActivatedRoute) {
}
getParams() {
this.route.queryParams.
subscribe(
(params: Params) => {
this.urlParams.id = params['id'];
this.urlParams.name = params['name']
}
)
return this.urlParams;
}
}
I wanted my service return parameters, but when I cal this service in my component I'm getting 'id' and 'name' undefined