Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70429

Global project counter with behavior subject

$
0
0

@iondo wrote:

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!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70429

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>