我在AngularJS v1.6中對Redux功能使用「redux-observable」。 下面的代碼是一個史詩在Redux中注入服務Epic Angular JS
export const getAllBidsAPI : any = (action$: ActionsObservable<any>, store: any, { customerService = CustomerService }) =>
action$.ofType(GET_ALL_BID)
.mergeMap((action : any) =>
Observable.fromPromise(customerService.getCustomers())
.map((res: any) => ({type : GET_ALL_BID_SUCCESS , payload : res.data.bid}))
);
這裏的CustomerService無法識別。我猜,它沒有注入。
const rootEpic = combineEpics(
getAllBidsAPI
);
const rootReducer = combineReducers({
bidReducer
});
const epicMiddleware = createEpicMiddleware(rootEpic, {
dependencies : {CustomerService}
});
export const store = createStore(
rootReducer,
applyMiddleware(epicMiddleware)
);
這就是我們在Epic中添加CustomerService作爲依賴關係的地方。但是,我得到錯誤。
無法讀取的不確定
你如何解決這種依賴關係? – Hitmands
@Hitmands解決依賴關係的確切意思是什麼? –
AngularJS(1. *)具有'$ injector'對象,這意味着您只需註冊依賴關係並僅在框架允許的情況下(組件,服務,控制器等)使用它們。那麼,你如何解決'customerService'小寫?你做了:'dependencies:{CustomerService}'大寫... – Hitmands