创建Reducer时出错

时间:2017-08-31 11:15:54

标签: angular typescript ngrx

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 { }

我的reduce.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 
        }
    }

1 个答案:

答案 0 :(得分:0)

您需要将reducer导出为函数

而不是

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

使用

 getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.your_container,fragment,fragment.TAG)
            .addToBackStack(null)
            .commit();