2017-10-06 95 views
0

我有一個平均APP。我有給我從MongoDB中的對象服務: 控制檯顯示:對象中的數組無法訪問打印稿

enter image description here

這是代碼:

塊引用

export class AllocatViewComponent implements OnInit { 

equipment; 


constructor(
private location: Location, 
private activatedRoute: ActivatedRoute, 
private router: Router, 
private equipmentService: EquipmentService, 
) { } 


@ViewChild('myModal') 
modal: BsModalComponent; 

@ViewChild('deleteModal') 
modal2: BsModalComponent; 

ngOnInit() { 

this.equipmentService.getOneById(this.currentUrl.id).subscribe(data => { 
    // Check if GET request was success or not 
    if (!data.success) { 
    this.messageClass = 'alert alert-danger'; // Set bootstrap error class 
    this.message = data.message; // Set error message 
    } else { 
    this.equipment =data.equipment; 
    console.log(this.equipment) // log that i share 
    } 
    }); 
    } 

    save(form){ 

    var port = { 
    numberPort: this.portToEdit.numberPort, 
    connector: "", 
    speedCircuit: "", 
    status: "Available", 
    function: "", 
    serviceType: "", 
    network: "", 
    connectedTo: "", 
    customerName: "", 
    addressCustomer: "", 
    lelisID: form.controls.lelisID.value, 
    requester: "", 
    dateRequester: Date, 
    carrier: "" 
} 


this.modal.close(); 
} 


} 

我怎樣才能訪問this.equipment.cards [「x」]。ports [「y」]。狀態 我試過但是:[ts]屬性'卡'沒有xist on type'{}'

謝謝!

+0

你應該可以用'this.equiment [「property」]'來訪問它嗎? –

回答

0

由於您聲明瞭一個普通對象,因此編譯器無法識別設置爲this.equipment的屬性。試着做this.equipment["cards"]["x"].ports["y"].status

+1

謝謝!!!!現在我可以訪問了! –