我在ngxs中使用模型时遇到问题。我必须使用其他模型将数据传递到api并从api获取数据
我基本上有一个Report模型和NetIncome模型。由于我的代码存在错误,我将如何集成它们。我只能使用一种模型?或者我该如何修改我的模型?
我只想在Angular应用上获得最佳实践,所以我希望分配适当的模型。随意重组或更改很多代码,等等...
这里是stackblitz链接Click Here
@Action(GetNetIncomes)
GetNetIncomes(ctx: StateContext<ReportStateModel>, { payload }: GetNetIncomes) {
return this.reportsService.getNetIncomes(payload).pipe(
tap((result: NetIncome) => {
ctx.patchState({
net_incomes: result,
});
}),
catchError((err) => {
console.log(err);
return throwError(err);
})
);
}
getNetIncomes返回一个Reports或Report []数组,然后在不符合要求时尝试将其强制转换为NetIncome。我建议在点击之前添加一个映射运算符,以将结果转换为NetIncome或在ReportStateModel中更改net_incomes的类型