Мне нужно получить параметр маршрута в моем сервисе
import {Inject, Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs';
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
@Injectable({
providedIn: 'any'
})
export class LocationService {
constructor(
private router: Router,
private route: ActivatedRoute
) {
console.log('ddd ', );
this.router.events.subscribe((data) => {
if (data instanceof NavigationEnd) {
console.log('this.route.snapshot.params[\'city\']; ', this.route.firstChild.snapshot.params['city']);
}
});
}
}
в компоненте, который
this.router.events.subscribe((data) => {
if (data instanceof NavigationEnd) {
console.log('this.route.snapshot.params[\'city\']; ', this.route.firstChild.snapshot.params['city']);
}
});
работает правильно, но в сервисе city
не определен
Если я предоставляю службу определения местоположения в компоненте
@Component({
selector: 'app-city-chooser',
templateUrl: './city-chooser.component.html',
styleUrls: ['./city-chooser.component.scss'],
providers: [LocationSerivce]
})
, моя служба вызывает дважды (я использую свою службу в другом компоненте)
Как получить параметры маршрута в моей службе?
UPD: в проекте два модуля !!! BasicModule и DashboardModule