angular – 无法解析ngrx / store Action的所有参数
发布时间:2020-12-17 17:42:25 所属栏目:安全 来源:网络整理
导读:我正在尝试使用以下内容创建@ngrx / store操作 import { ActionReducer,Action } from '@ngrx/store'import { StoreService } from 'ng2-storeservice'import { IPatient,Patient } from './patient.service'export class PatientActions { static ADD = '[P
我正在尝试使用以下内容创建@ngrx / store操作
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( {},action.payload ); default: return state; } }; 服务适当地放置在可识别的模块中. 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) 任何帮助表示赞赏. 解决方法
您需要在PatientsAction类上添加@Injectable装饰器.这就是Angular如何向类中添加元数据.没有元数据,Angular将不知道如何/注入什么.
也可以看看: > When do we need to use @Injectable on our services in Angular2? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |