RaviTeja RaviTeja - 17 days ago 9
TypeScript Question

How to get the checked values from browser in angular2(facing ORIGINAL EXCEPTION: Cannot read property 'push' of undefined Error)

im trying to get the values of check boxes which are checked below is my html code and im facing below error when im trying to achieve this

ORIGINAL EXCEPTION: Cannot read property 'push' of undefined

> <input type="checkbox" name="options"
> (click)="checkvalues(files)"></td>


checkvalues() method in typescript

checkvalues(filesinput:any){
this.entries.push(filesinput);
console.log(this.entries);
}


Please help me out

Answer

Seems like your this.entries is not defined?!

Try this:

checkvalues(filesinput:any) {
   if (!this.entries) this.entries = [];
   this.entries.push(filesinput);
   console.log(this.entries);
}