gpt4 book ai didi

angular - 错误TypeError : Cannot read property 'codeSprint' of undefined at Object.eval [as updateRenderer] using Angular

转载 作者:行者123 更新时间:2023-12-03 08:38:55 25 4
gpt4 key购买 nike

有人可以解释可能出了什么问题吗?我收到此错误

ERROR TypeError: Cannot read property 'codeSprint' of undefined
at Object.eval [as updateRenderer] (SprintComponent.html:12)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:45294)
at checkAndUpdateView (core.js:44277)
在SprintComponent.html中:
<div ngFor="let sprint of sprints">
{{sprint.codeSprint}}
{{sprint.title}}
</div>
在SprintComponent.ts中:
sprints : Sprint[];
在SprintService.ts中:
getSprints(): Observable<Sprint[]> {
const token = localStorage.getItem('kno');
const rqwstrId = localStorage.getItem('rqwstrId');
let header = new HttpHeaders('Content-Type: application/json; charset=UTF-8');
header = header.append('kno',token);
header = header.append('rqwstrId', rqwstrId);
let param = new HttpParams().set('code',"Koon52");
return this.http.get<Sprint[]>(this.baseUrl + '/v1/sprints/', {headers : header , params : param});
}
将Sprint作为具有以下属性的类:
export class Sprint {
kno:string;
rqwstrId : string;
code: string;
codeSprint : string;
dateDebut : string;
dateFin : string;
title : string;

constructor() {
}
}
同时,当我将其记录在控制台中时,它显示如下数据:
SprintComponent.html:9 ERROR TypeError: Cannot read property 'codeSprint' of undefined
at Object.eval [as updateRenderer] (SprintComponent.html:9)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:45294)
at checkAndUpdateView (core.js:44277)
at callViewAction (core.js:44637)
at execComponentViewsAction (core.js:44565)
at checkAndUpdateView (core.js:44278)
at callViewAction (core.js:44637)
at execEmbeddedViewsAction (core.js:44594)
at checkAndUpdateView (core.js:44272)
at callViewAction (core.js:44637)
我在SprintComponent中这样调用getSprints方法:
ngOnInit() : void {
this.sprintService.getSprints().subscribe(
data =>
{
this.sprints = data;
}
);
谢谢!

最佳答案

您需要在组件

sprints:any[]=[];
in your ngoninit

this.service.getSprints().subscribe((response) => {
this.sprints=response as any
});

)}
中订阅该方法
在您的component.html
<div *ngFor="let sprint of sprintd">
{{sprint.codeSprint}}
{{sprint.title}}
</div>

关于angular - 错误TypeError : Cannot read property 'codeSprint' of undefined at Object.eval [as updateRenderer] using Angular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64019494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com