The feature name "channels" does not exist in the state, therefore createFeatureSelector...

Discussão em 'Angular' iniciado por Said Gadzhiev, Abril 26, 2025.

  1. I am trying to get a variable when subscring to an observable like so:

    channels$!: Observable<Channel[]>;
    channels: Channel[] = [];

    ngOnInit(): void {
    this.store.dispatch(ChannelsActions.LoadAll());

    this.channels$ = this.store.select(selectAllChannels);

    this.channels$.subscribe((channels) => {
    this.channels = channels;
    });
    }


    But i do get this warning message which I believe is the reason why this.channels is always undefined:

    @ngrx/store: The feature name "channels" does not exist in the state, therefore createFeatureSelector cannot access it. Be sure it is imported in a loaded module using StoreModule.forRoot('channels', ...) or StoreModule.forFeature('channels', ...). If the default state is intended to be undefined, as is the case with router state, this development-only warning message can be ignored.

    Here is app.module.ts for reference:

    @NgModule({
    declarations: [AppComponent],
    imports: [
    BrowserModule,
    CommonModule,
    AppRoutingModule,
    StoreModule.forFeature('channels', channelsReducer),
    ....


    Here is selector.ts for reference:

    export const selectChannelsState =
    createFeatureSelector<ChannelsState>('channels');

    export const selectAllChannels = createSelector(
    selectChannelsState,
    (state: ChannelsState) => {
    console.log('Channels state:', state?.channels);
    return state?.channels;
    }
    );


    I tried changing StoreModule.forRoot => StoreModule.forFeature. Same outome. I tried to console log in the store components (reducer, effects...) None of those gets triggered so I assume the problem lies somewhere between the ngOnInit or the selector

    Continue reading...

Compartilhe esta Página