我有一个API,该API返回以下JSON
{
"error": false,
"success": true,
"response": "{\"events\": [\"_campaign.send\", \"_SMS.FAILURE\", \"_SMS.SUCCESS\", \"_email.open\", \"_email.delivered\", \"_email.send\", \"_test.event_stream\"], \"count\": [4, 3, 2, 2, 1, 1, 1]}"
}
在Angular应用程序中,我只是在控制台上打印响应
this.http.post(environment.getCampaignEvents, {
"": "",
}).subscribe(data => {
this.campaignEvents = data;
//this.spinner.hide();
if (this.campaignEvents.success === false) {
console.log('Get Campaign events = fail');
this.statusText = this.campaignEvents.msg;
this.campaignEventsResponseMessage = this.statusText;
this.toasterService.pop('error', 'Error!', this.campaignEventsResponseMessage);
this.campaignEventsResponseMessage = this.campaignEventsResponseMessage.msg;
} else {
console.log('Get Campaign events = passed');
this.CampaignList=this.campaignEvents.response;
this.CampaignList = JSON.parse(this.CampaignList);
console.log(this.CampaignList);
}
}
通过此行console.log(this.CampaignList); ,我在浏览器上遇到错误,错误不断增加,并不断在浏览器上抛出错误。
答案 0 :(得分:1)
我认为错误不是由console.log
引起的。看到您得到的错误:问题出现在
at Object.eval [as updateDirectives](CampaignManagementComponent.html:24)
我建议您在上述行(24)周围添加一些东西,以防止在需要的数据出现之前进行渲染。 (可能是一个*ngFor
结构性指令,其中您给出了null或on对象而不是数组是我的猜测。(我的意思是,您绑定的数据在第一次渲染时为null或对象-尝试停止渲染直到http通话结束)