错误TypeError:无法使用Angular读取Object.eval [未定义的属性'codeSprint'[作为updateRenderer]

时间:2020-09-23 00:47:21

标签: angular error-handling

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

base

在SprintComponent.html中:

In [70]: a.base
Out[70]: array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14])
In [71]: a = a[2:,:]
In [72]: a
Out[72]: array([[10, 11, 12, 13, 14]])

在SprintComponent.ts中:

In [73]: a.base
Out[73]: array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14])

在SprintService.ts中:

In [74]: a=np.arange(15).reshape(3,5).copy()
In [75]: a.base
In [76]: a = a[2:,:]
In [77]: a.base
Out[77]: 
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])

将Sprint作为具有以下属性的类:

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)

同时我在控制台中登录时,它显示的数据如下:

<div ngFor="let sprint of sprints">
    {{sprint.codeSprint}}
    {{sprint.title}}
  </div>

我在SprintComponent中这样调用getSprints方法:

sprints : Sprint[];

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要在组件中订阅方法

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>