- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试执行 API 调用并将现有数据与现有数据合并(合并是在 addMissingData 中完成的)。
当我尝试调用时出现错误:
Uncaught TypeError: You provided 'undefined' where a stream wasexpected. You can provide an Observable, Promise, Array, or Iterable.
at subscribeTo (subscribeTo.js:27)at subscribeToResult (subscribeToResult.js:11)at MergeMapSubscriber._innerSub (mergeMap.js:59)at MergeMapSubscriber._tryNext (mergeMap.js:53)at MergeMapSubscriber._next (mergeMap.js:36)at MergeMapSubscriber.next (Subscriber.js:49)at MapSubscriber._next (map.js:35)at MapSubscriber.next (Subscriber.js:49)at CatchSubscriber._next (Subscriber.js:72)at CatchSubscriber.next (Subscriber.js:49)
GetStepWiseMasterData$ = createEffect(() => this.actions$.pipe(
ofType(MasterDataAction.getCustomerMasterData),
switchMap((action) => {
return this.dataService.GetDataAsync(action.stepEnum).pipe(
map((response) => {
return {
isSuccess: response.isSuccess,
newData: response.data,
data: action.data,
};
}),
mergeMap((response) => {
if (response.isSuccess) {
this.addMissingData(response.newData, action.data).then(result => {
return [DataAction.getCustomerDataComplete({ customerData: result })];
});
} else {
return [DataAction.getCustomerDataFailed({ customerData: {} })];
}
}),
catchError(() => EMPTY)
);
})
));
async addMissingData(newMasterData: BusinessPartnerMasterDataVM, existingMasterData: BusinessPartnerMasterDataVM = {}): Promise<any> {
const omitNullValues = masterDataObj => new Promise((resolve) => {
// filter with property name and delete all properties that are null
Object.keys(masterDataObj).filter(propertyName => masterDataObj[propertyName] === null).forEach(propertyName => delete(masterDataObj[propertyName]));
resolve(masterDataObj);
});
const masterNew = await omitNullValues(newMasterData);
const masterOld = await omitNullValues(existingMasterData);
const ret = Object.assign({}, masterNew, masterOld);
return ret;
}
最佳答案
好像你的问题发生在这个区域,
mergeMap((response) => {
if (response.isSuccess) {
this.addMissingData(response.newData, action.data).then(result => {
return [DataAction.getCustomerDataComplete({ customerData: result })];
});
} else {
return [DataAction.getCustomerDataFailed({ customerData: {} })];
}
})
这里没有任何返回
if (response.isSuccess)
条件分支。据我了解,您想调用两个 API
getCustomerMasterData
getCustomerMasterData
的结果,您要调用addMissingData
GetStepWiseMasterData$ = createEffect(() => this.actions$.pipe(
ofType(MasterDataAction.getCustomerMasterData),
switchMap((action) => {
return from(this.combinedFunction(action)).pipe(
map((result) => {
return { masterData: result };
}),
switchMap((result) => {
return [MasterDataAction.getCustomerDataComplete(result)];
})
);
})
));
async combinedFunction(action) {
const response = await this.dataService.GetDataAsync(action.stepEnum).toPromise();
if (!response.isSuccess) {
return {};
}
return await this.addMissingData(response.newData, action.data);
}
from
需要将 Promise 转换为可以从
rxjs
导入的 Observable ,或者您可以修改
combinedFunction
返回一个 Observable。
关于angular - NgRx: 得到 'You provided ' undefined' where a stream is expected.'当调用有效的完整 Action 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63409991/
我是一名优秀的程序员,十分优秀!