Reputation: 10765
I have a JSON array of similar items , example of one item is as follow :
{
"ownerID": "rkjgAs40NEuSJfp4jquNYQ",
"defaultPriceScheduleID": null,
"autoForward": false,
"id": "44685751902",
"name": "1864 End Leaf B18",
"description": "1864 End Leaf B18",
"quantityMultiplier": 1,
"shipWeight": null,
"shipHeight": null,
"shipWidth": null,
"shipLength": null,
"active": true,
"specCount": 26,
"variantCount": 0,
"shipFromAddressID": null,
"inventory": null,
"defaultSupplierID": null,
"xp": {
"SAP-Description": "1864 End Leaf B18",
"Status": "Active",
"Brand-Name": "!",
"Product-Group": "Y6Z-vee5WUytwna-WsSxfw",
"UPC-Each": "44685751902",
"productAttributesComplete": true,
"ImageURLs": [
null,
null,
null,
null,
null,
null
],
"Ecommerce": {
}
}
}
I have a one dropdown in angular in which I want to bind the name to 'name' and value to 'product-group' but it says xp.product-group
is undefined .
this is the code I am using to get the product list in ts file
getProductList(){
this.service.getProductList().subscribe(data=>{
this.ProductList=data;
console.log(this.ProductList[0].xp['Product-Group']);
});
}
and here is dropdown html
<div class="form-group">
<label for="pname">Product Name</label>
<select (change)="onPOptionsSelected(mySelect.value)" #mySelect >
<option *ngFor="let prod of ProductList" [value]="prod.xp['Product-Group']" class="form-control" id="pname" >{{prod.name}} </option>
</select>
</div>
Upvotes: 1
Views: 86
Reputation: 1780
Use [value]="prod.xp && prod.xp['Product-Group']"
in dropdown html in case prod.xp is null or undefined.
Upvotes: 1
Reputation: 2698
can you please try prod.xp.product-Group to access the value of current item you want to access.
Upvotes: 0