Reputation: 59
How can I add or push value into a array in ionic 3?
my code in .ts
optionsArray : Array<{productOptionId : string , productOptionValueId : string}>;
...
checkCheckbox(V,ProductOI,ProductOVI){
if ( V ) {
this.optionsArray.push({ productOptionId : ProductOI , productOptionValueId : ProductOVI });
}
}
The error message is :
Cannot read property 'push' of undefined
Upvotes: 1
Views: 5448
Reputation: 201
You have to initialize your variable first.
optionsArray : Array<{productOptionId : string , productOptionValueId : string}> = [];
Upvotes: 2