Hello,
I´m trying to share my count results to two other components after filtering projects. When I filter my projects I want to share the count to two other components. And when I repeat the filter I want update the count for the other components.
I think the most important file is the service:
export class ProjectService {
api = '/project';
private countProject = new BehaviorSubject(0);
constructor(private http: HttpClient) {}
getCount(term?, queryString?): Observable<Filter> {
return this.http.post<Filter>(`${this.api}/count.json`, {
qf: queryString,
q: [{
what: {id: 13},
search: {value: term}
}]
});
}
getCountObservable(): Observable<number> {
return this.countProject.asObservable();
}
And my typescript in one of my components (FilterComponent):
countProject = 0;
constructor( ) {
this.projectService.getCountObservable().subscribe(res => {
this.countProject = res;
});
}
Any idea how I can update the countProject property for the other components, in that case only FilterComponent?
Thanks for any tip!