Multiple subscription problem on ngOnInit() dashboard in Angular App

Discussão em 'Angular' iniciado por Shakalya Uttam, Dezembro 18, 2024.

  1. I have dashboard API hit on ngOnInit() plus a global states of region store and bussiness dropdowns as a subscriptions. These dropdowns are used in many other pages as well.

    case 1: on landing dashboard page first time. Dashboard api hit first time and any change in dropdown detection again hits dashboard and refreshes filtered data.

    case 2: now you made 3 filters set and reloads the page. 3 subscriber emits its preselected values and now on dashboard page. getDashboard() hits 4 times and as onInit and 3 from different subscriptions. How to handle this?

    it triggered 1 more time when in encounter 1 more queryParams subscription on internal page.

    ngOnInit() {
    this.getDashboard();

    this.regionState$$ = this.api.regionState.subscribe(res=>{
    this.getDashboard();
    });

    this.storeState$$ = this.api.storeState.subscribe(res=>{
    this.getDashboard();
    });

    this.businessState$$ = this.api.businessState.subscribe(res=>{
    this.getDashboard();
    });

    this.activatedRoute.queryParams.subscribe(params => {
    this.getDashboard();
    }
    }


    I tried changing behaviour subject to subject so only emits when any value is their in filters otherwise it was hitting all the time 4 times.

    I tries PromisAll() that will not detect any further filter changes as it runs only one time.

    Continue reading...

Compartilhe esta Página