У меня есть служба данных (dataservice), которая получает данные на основе переданного параметра. Dataservice вводится во вторую службу (resultservice), которая будет вызывать методы службы данных для получения данных.
В моем angular компоненте я вставляю resultservice, но мне нужно передать ему параметр GroupId. Как правильно это сделать?
import { Injectable } from '@angular/core';
import { Subject, Observable } from 'rxjs';
import { DataService} from './data.service';
@Injectable({
providedIn: 'root'
})
export class ResultService {
protected groupId;
private results$ = new Subject<any>();
constructor(
private dataService: DataService,
groupId: number
) {
this.dataService.getResults(groupId) //this groupId value is what I need to pass in from my component
.subscribe(res => {
this.results$.next(res);
})
}
getResults(): Observable<any> {
return this.results$.asObservable();
}
}
Компонент
constructor(
private activatedRoute: ActivatedRoute,
private competitiondata: CompetitionDataService,
private platform: Platform,
private resultService: ResultService
) { }
ngOnInit() {
this.activatedRoute.params.subscribe(params =>
this.groupId = params['groupId']; //how do I pass this value to the ResultService so that it can be passed to the DataService???
this.results = this.resultService.getResults();
}
}