Having trouble iterating through a TypeScript array. Here are the methods I'm using:
getNotification(evt: string, rowIndex: number) {
console.log("Production order: law has changed to " + evt + " " + rowIndex);
var select = document.getElementsByName("ProductId-" + rowIndex);
this.removeOptions(select);
if ((evt != null) && (evt != "")) {
let productsByLaw: IProduct[];
productsByLaw = this.products.filter(x => x.lawId == +evt);
for (let product in productsByLaw) {
select.options[select.options.length] = new Option(product.name, product.productid);
}
}
}
removeOptions(selectbox : any) {
var i;
for (i = selectbox.options.length - 1; i >= 0; i--) {
selectbox.remove(i);
}
}
I'm unsure about
var select = document.getElementsByName("ProductId-" + rowIndex);
as the proper way to retrieve an html select
. When trying select.options[select.options.length]
, I encounter this compiler time error:
Error TS2339 (TS) Property 'options' does not exist on type 'NodeListOf'.
Is there a better approach to getting a select
element in TypeScript?