创建还原器的错误


ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 8:51 in the original .ts file), resolving symbol LocationStore in /root/ngrxbasedproject/src/app/reducer/reducer.ts, resolving symbol AppModule in /root/ngrxbasedproject/src/app/app.module.ts, resolving symbol AppModule in /root/ngrxbasedproject/src/app/app.module.ts, resolving symbol AppModule in /root/ngrxbasedproject/src/app/app.module.ts

我不为什么会发生。

我的app.module.ts是

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { LocationStore } from './reducer/reducer';
import { Store, StoreModule } from "@ngrx/store";

@NgModule({
    declarations: [
    AppComponent
  ],
  imports: [
  BrowserModule,
  StoreModule.provideStore({LocationStore}),
],
providers: [],
bootstrap: [AppComponent]
})Ï
export class AppModule { }

我的ready.ts是

import {Action , ActionReducer} from '@ngrx/store';
const  initialState: any = {
    selectedLocation : '',
    allLocations : []
};
export const LocationStore : ActionReducer<any> = 
     (state = initialState ,  action : Action) =>  {
        switch(action.type){
            case 'LOCATION_UPDATED':
                action.payload =  {city : 'chandigarh'}
                console.log(action.payload);
                console.log(state);
                return Object.assign({}, state, action.payload);
            case 'LOCATION_REC':
                 console.log(state);
                return 'dfdgddf';
                // Final Data {city : 'chandigarh' ,state : 'chandi'}
                // Final Data 
        }
    }

您需要将还原器导出为功能

而不是

export const LocationStore : ActionReducer<any> = 
     (state = initialState ,  action : Action) =>  {

使用

export function LocationStore : ActionReducer<any> = 
     (state = initialState ,  action : Action) =>  {

最新更新