TYPESCRIPT ARRAY WITH INTERFACE ERROR easy answer

11 views
Skip to first unread message

j_rough

unread,
May 25, 2020, 8:08:12 PM5/25/20
to Angular and AngularJS discussion
The error is on pID. Error is "An index signature must have exactly 1 parameter". I don't know how to correct the index but I need an array of products using Interface type. Thanks Very much,

interface IprodList {
   [ pId: string,productName: string,    productPrice: numbproductAvailable: string]
}
  var product:IprodList[]=[285,'Samsung Galaxy Note 7'59000,'Available'];
  product.push([286'Samsung Galaxy S6 Edge',53499,'Available']);
  product.push([287,'Nokia Lumia 640XL',14990'Out of Stock']);

Ankita Sarolkar

unread,
May 25, 2020, 10:22:37 PM5/25/20
to ang...@googlegroups.com
var productarr: IprodList[] = [
    { "pId":"285", "productName":"Samsung Galaxy Note 7", ''productPrice":"59000","productAvailable":"Available" },
    { "pId":"286", "productName":"Samsung Galaxy Note 7", ''productPrice":"59000","productAvailable":"Available" }
];

When you are pushing data into the array,


let productarray= IprodList[];
let prodData =  {} as IprodList;
prodData.pId = 285;
prodData.prodctName = 'something';
...

productarray.push(prodData);



--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/5b93c11f-909d-4227-a7dc-b4dd6e01188f%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages