简体   繁体   中英

Adding objects to a list in angular 2 typescript

I am facing a problem to push data in a list here is my code.

labelListSelected: Label[];

onChange(object,flag){
   if(flag==false){      
           this.labelListSelected.push(object);
   }
   console.log(this.labelListSelected);
     //   console.log(object.Id+" : "+flag);
}

i guess its null pointer, change to:

labelListSelected: Label[] = [];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM