我有一個創建對象的方法函數。我在這裏的功能Angular2錯誤無法讀取屬性
packetdata:any[];
ngOnInit() {
this.service.getonepacket(this.nopacket).subscribe(
data => {
return this.packetdata = data;
},
error => console.log(this.errorMessage = <any>error)
)
}
如果我使用控制檯日誌this.packet就會導致物體像這樣
Object {idpacket: 3, packetname: "Packet C", packetdesc: "SMS 20 sms/hari, Storage 20Gb", packetprize: "Rp. 300.000/bulan", packettime: 30}
我試圖把那對我的表中的每個值這樣
<h3 class="page-header">Your Bill Information</h3>
<table class="table table-striped">
<tr>
<th *ngFor="let item of packetdata"> Packet Name </th>
<td>{{item.packetname}}</td>
</tr>
<tr>
<th *ngFor="let item of packetdata"> Description </th>
<td> {{item.packetdesc}} </td>
</tr>
<tr>
<th *ngFor="let item of packetdata"> Prize </th>
<td> {{item.packetprize}} </td>
</tr>
<tr>
<th *ngFor="let item of packetdata"> Minimal Contract time (day) </th>
<td> {{item.packettime}} </td>
</tr>
</table>
但它返回錯誤錯誤無法讀取屬性。
如何解決這個問題?
請發佈確切的錯誤信息。 –
像那個先生@GünterZöchbauer 錯誤:./BillComponent類中的錯誤BillComponent - 內聯模板:5:8引起的:無法讀取未定義的屬性'packetname' – dedypuji