How to correct this flow in latest Angular?

Discussão em 'Angular' iniciado por Nikunj Guna, Janeiro 15, 2025.

  1. Nikunj Guna

    Nikunj Guna Guest

    I have been working on this using latest Angular signals and rxResource, but came to this issue

    // this will make API call for chain everytime lastLoadedscript is set
    myResource = rxResource<{ [key: string]: strategy[] }, { seg: number, sid: number }>({
    request: () => {
    let script = this.stateService.lastLoadedScript()
    let tempReq = {
    seg: script.id || 0,
    sid: script.sid
    }
    return tempReq
    },
    loader: ({ request }) => {
    return this.myService.getExplist(request).pipe(
    switchMap((expiryDetails: ExpiryDetails[]) => {
    this.expiryList = expiryDetails;
    this.expirySortname = this.expiryList.map(e => e.sortname);
    let script = this.stateService.lastLoadedScript();
    let tempObj = {
    "StrategyName": "*",
    "Symbol": script.name,
    "ExpiryJulian": this.expiryList[this.prebuiltExpiry()].expiry
    };
    return this.myService.getstrategy(tempObj).pipe(
    map(resp => {
    if (resp['status'] != 'success') {
    throw new Error('Invalid resp');
    }
    return processData(resp['data'])
    })
    );
    })
    );
    }
    })```




    Issue here is that expList is getting each time, I need getstrategy for different expiry goal is

    1. On page load call explist once it's response came call getStrategy
    2. Do all subsequent call of getstrategy with simple myResource.reload() with selected expiry but dont make expiry api call.
    3. When lastLoadedScript changes repeat step 1. i.e: call exp then call get strategy

    I tried seperate resource for exp but it won't work as getStrat must be call only after explist is available

    Continue reading...

Compartilhe esta Página