我有一个卑鄙的APP。我有一个服务,从mongoDB给我一个对象: 控制台显示:
这是代码:
块引用
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”]。status 我试过但是:[ts]属性'卡''在类型'{}'上不存在
谢谢!
答案 0 :(得分:0)
由于您已声明了普通对象,因此编译器无法识别设置为this.equipment
的属性。尝试this.equipment["cards"]["x"].ports["y"].status
。