Sumchans
Sumchans

Reputation: 3784

Angular TypeScript pushing items to array errors

export class PickGroupService {
  channelList: any[];
  pick5West = ['783', '679', '934', '946', '800'];
  thePicks: any[];

  constructor(private channels: ChannelsService) { this.channelList = this.channels.getChannels(); }

  getPickSet(pick, region) {
    if (pick === 'pick5') {
      switch (region) {
        case 'west':
        for (let i = 0; i < this.pick5West.length; i++) {
          this.thePicks.push((this.channelList.filter(x => x.pickCode === this.pick5West[i]));
        }
        console.log(this.thePicks);
  }
}

} } Just wondering whats wrong with this code, it says : ERROR TypeError: this_1.thePicks is undefined on browser console. Please advise!

Upvotes: 0

Views: 52

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222682

Initialize it to an empty array,

 thePicks: any[] = [];

Upvotes: 4

Related Questions