angular - Angular 7 Promise 效果不佳?一次成功块,错误块
问题描述
我正在将我的应用程序 Angular 2(Http) 转换为 Angular 7(HttpClient) 我不明白为什么会这样。我的代码
service.ts
return this.http.get(serviceUrl).toPromise().then((data:any) => {
return data;
})
组件.ts
this.myService.getList()
.then((rmanFmvRulesDefList: any) => {
$.unblockUI();
console.log('list',rmanFmvRulesDefList);
this.datasource = rmanFmvRulesDefList.content;
this.rmanFmvRulesDefList = rmanFmvRulesDefList.content;
if (this.rmanFmvRulesDefList.length > 0) {
for (let i = 0; i < rmanFmvRulesDefList.content.length; i++) {
this.rmanFmvRulesDefList1.push({
'fmvRuleName': rmanFmvRulesDefList.content[i].fmvRuleName,
'fmvCategory': rmanFmvRulesDefList.content[i].fmvCategory
})
}
/* for (let i = 0; i < rmanFmvRulesDefList.content.length; i++) {
this.rmanFmvRulesDefList1.push({
'fmvRuleName': rmanFmvRulesDefList.content[i].fmvRuleName,
'fmvCategory': rmanFmvRulesDefList.content[i].fmvCategory,
'fmvType': rmanFmvRulesDefList.content[i].fmvType,
'fmvRuleStatus': rmanFmvRulesDefList.content[i].fmvRuleStatus,
'fmvPrice': rmanFmvRulesDefList.content[i].fmvPrice ,
'min': formatNumber(rmanFmvRulesDefList.content[i].min , '1.2-2'),
'median': formatNumber(rmanFmvRulesDefList.content[i].median , '1.2-2'),
'max': formatNumber(rmanFmvRulesDefList.content[i].max , '1.2-2')
})
}*/
}
console.log(this.rmanFmvRulesDefList1, 'rman fm list')
}).catch((err: any) => {
console.log('erre block')
this.growlMsgs=[{severity:'error', summary:'Error Message', detail:'Error occured while getting data!!'}];
$.unblockUI();
});
从我的服务中,我得到了 100 个列表项
问题:我的success(then), error(then) 在这种情况下一次阻止调用
如果我准备具有两个属性的数组(this.rmanFmvRulesDefList1),它工作正常
2. 但是如果我准备了具有 8 个属性的数组,它将进入 catch 块,并执行代码
请任何人帮助我这里发生了什么
解决方案
推荐阅读
- javascript - 如何设置axios超时
- angular - PrimeNG 添加自定义标题文本
- android - Android 12 飞溅白色背景
- visual-studio-code - 无论如何在关闭内核之前将环境变量保存在vscode jupyter中?
- r - ggcorrplot,多列,按因子分组
- c# - 如何在应用程序中提供虚拟目录路径
- sql - 在运行时使用 JDBCTemplate 创建表
- javascript - 打字稿的fineOneAndUpdate错误:“文档”类型上不存在属性“findOneAndUpdate”
. 猫鼬 - django - 在没有端口号的 ubuntu 网络服务器上加载 Flask 应用程序
- flutter - 如何处理稍后初始化的不可空变量?