Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't resolve all parameters for an ngrx/store Action

I am attempting to create an @ngrx/store action with the following

import { ActionReducer, Action } from '@ngrx/store'
import { StoreService } from 'ng2-storeservice'
import { IPatient, Patient } from './patient.service'

export class PatientActions {
  static ADD = '[Patient] ADD';
  static REMOVE = '[Patient] REMOVE';
  static RESET = '[Patient] RESET';

  constructor( public store: StoreService ) { }

  add( path: string, payload: IPatient ) {
    this.store.dispatch( PatientActions.ADD, payload );
  }

  remove( path: string, payload: IPatient ) {
    this.store.dispatch( PatientActions.REMOVE, payload )
  }

  reset( path: string, payload: IPatient ) {
    this.store.dispatch( PatientActions.RESET, payload )
  }
}

export const patient: ActionReducer<IPatient> = (
    state: IPatient = new Patient(), action: Action ) => {
  switch ( action.type ) {
    case PatientActions.ADD:
      return Object.assign( state, action.payload );

    case PatientActions.REMOVE:
      return Object.assign( {}, state, action.payload );

    case PatientActions.RESET:
      return Object.assign( {}, state, action.payload );

    default:
      return state;
  }
};

Services are appropriately placed in module that is recognised. Running the application gives the following error

metadata_resolver.js:499Uncaught Error: Can't resolve all parameters for PatientActions: (?).
    at CompileMetadataResolver.getDependenciesMetadata (http://localhost:4200/main.bundle.js:31019:19)
    at CompileMetadataResolver.getTypeMetadata (http://localhost:4200/main.bundle.js:30920:26)
    at http://localhost:4200/main.bundle.js:31063:41
    at Array.forEach (native)
    at CompileMetadataResolver.getProvidersMetadata (http://localhost:4200/main.bundle.js:31043:19)
    at http://localhost:4200/main.bundle.js:30741:71
    at Array.forEach (native)
    at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/main.bundle.js:30732:44)
    at http://localhost:4200/main.bundle.js:30745:50
    at Array.forEach (native)

Any help is appreciated. ​

like image 535
st_clair_clarke Avatar asked Dec 22 '16 20:12

st_clair_clarke


People also ask

What is a good use case for NgRx store?

NgRx is a global state management library that helps decouple the Domain and Business layers from the Rendering layer. It's fully reactive. All changes can be listened to using simple Observables, which makes complex business scenarios easier to handle.

Where is NgRx store data is stored?

Where Does NgRx Store Data? NgRx stores the application state in an RxJS observable inside an Angular service called Store. At the same time, this service implements the Observable interface. So, when you subscribe to the store, the service actually forwards the subscription to the underlying observable.


1 Answers

You need to add the @Injectable decorator on the PatientsAction class. This is how Angular adds metadata to the class. Without the metadata, Angular will not know how/what to inject.

See Also:

  • When do we need to use @Injectable on our services in Angular2?
like image 166
Paul Samsotha Avatar answered Nov 15 '22 17:11

Paul Samsotha