0
votes

The error appears in app.module.ts. Relevant code:

import { createStore, Store } from 'redux';
import { rootReducer } from './redux-store/index';

const appStore = createStore(rootReducer);

@NgModule({
  providers: [
    { provide: 'AppStore', useValue: appStore }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

I am using the latest Angular-cli, and this didn't happen with previous versions. The full error text is:

ERROR in Error encountered resolving symbol values statically. Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler (position 251:14 in the original .ts file), resolving symbol createStore in /home/daco/handwork/Angular2/MileageStats2/node_modules/redux/index.d.ts, resolving symbol AppModule in /home/daco/handwork/Angular2/MileageStats2/src/app/app.module.ts, resolving symbol AppModule in /home/daco/handwork/Angular2/MileageStats2/src/app/app.module.ts, resolving symbol AppModule in /home/daco/handwork/Angular2/MileageStats2/src/app/app.module.ts

1

1 Answers

2
votes

Try using useFactory instead of useValue

export function appStoreFactory() {
 return createStore(rootReducer);
}

@NgModule({
  providers: [
    { provide: 'AppStore', useFactory: appStoreFactory }
  ],
  bootstrap: [AppComponent]
})

export class AppModule { }