Search code examples
angularselectorngrx

NGRX, filter from selector


I am using below selector:

export const selectorPersonData = createSelector(featureSelector, (state, props) => {
    try {
        return state.departmentData.filter(filt => filt.currentPosition.jobId === props.workSelectProps)
            .map(job => job.assignedJob
                .map(item => item.dealId));
    } catch (e) {
        return null;
    }
});

In returning I got [[idA,idB]]

I tried a lot of solution with flatMap etc... but I did not get:

[idA, idB]

And I would like to get that data from selector.

And there are a double map. Nested Maps.

 Map<namePersons, Map<workData, InformationModel>>>

Solution

  • Since you have nested map calls you will get nested arrays. You will need to flatten the returned arrays to get the desired results.

    Try:

    return [].concat.apply([], state.departmentData.filter(filt => filt.currentPosition.jobId === props.workSelectProps)
            .map(job => job.assignedJob
                .map(item => item.dealId)));
    

    HTH