I am trying to find out what is the best way to get the current route params in Angular 6.
At the moment I have to pass the ActivatedRoute
to the service's method as argument and then use it in the service.
export class MainComponent {
constructor(private dataService: DataService, private activeRoute: ActivatedRoute) { }
getChartsData() {
return this.dataService(this.activeRoute);
}
}
@Injectable({
providedIn: "root"
})
export class DataService {
getChartsData(activatedRoute) {
if (activatedRoute.snapshot.params['id']) {
...
} else {
...
}
}
}