ashe405
ashe405

Reputation: 59

how to add or push value to array in ionic 3

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

Answers (1)

xFly.Dragon
xFly.Dragon

Reputation: 201

You have to initialize your variable first.

optionsArray : Array<{productOptionId : string , productOptionValueId : string}> = [];

Upvotes: 2

Related Questions