Javascript 如何从对象数组在模板中显示属性
我只是尝试在模板中显示属性的值。但目前什么都没有显示 这就是组件:Javascript 如何从对象数组在模板中显示属性,javascript,angular,typescript,rxjs,Javascript,Angular,Typescript,Rxjs,我只是尝试在模板中显示属性的值。但目前什么都没有显示 这就是组件: export class ServerStatusComponent implements OnInit { snovieCollection: SnovietatusDto = {}; constructor(private snovierStatus: snovieStatusService) {} ngOnInit(): void { this.sensorStatus .getSens
export class ServerStatusComponent implements OnInit {
snovieCollection: SnovietatusDto = {};
constructor(private snovierStatus: snovieStatusService) {}
ngOnInit(): void {
this.sensorStatus
.getSensorStatuses()
.pipe(
map((data) => {
console.log(data.cameraSensors);
})
)
.subscribe((status) => {
});
}
}
这是模板:
<p>Camera sensoren</p>
<tr *ngFor="let camera of snovieStatusCollection.key|keyvalue">
test
<h3> {{camera | json}}</h3>
</tr>
所以我没有任何错误。但也没有显示任何内容。两件事:
你没有从地图上归还任何东西。因此,未定义的将被发送到订阅。使用tap来代替副作用。
您没有将响应分配给订阅中的此.sensorStatusCollection。
导出类ServerStatusComponent实现OnInit{
sensorStatusCollection:SensorStatusDto={};
构造函数私有sensorStatus:SensorStatusService{}
恩戈尼尼特:空虚{
这是我的身份
.GetSensorStatus
管
tapdata=>{/{
this.sensorStatusCollection=status;//这似乎也是错误的。sensorStatusCollection的类型似乎是SensorStatusDto,而您正在为其分配一个数组,这将导致类型不匹配。但是,如果不查看SensorStatusDto,很难说这一点。@Michael D它工作正常!!谢谢。我刚刚做了一些更改。但他把我推到了右边t方向。@Totalynewb:谢谢你指出,我已经更新了答案。我通过了wron dto。但是这一个是正确的:sensorStatusCollection:SensorStatusCollectionDto={};
0: {key: "T", latestTimestamp: "2021-03-12T10:09:00Z"}