title: Creating Dummy Model In Angular
body: <p>I trying to create a dummy model in Angular to get values from back end. But it's throwing some error because of array.</p>
  
  <p><strong>abc.ts</strong></p>
  
  <pre><code>export class abc {
  
      date: Date;
      time: string;
      ABC_Info: [{
              item: string,
              quantity: number,
              a: number
          },
          {
              item: string,
              quantity: number,
              a: number
          }
      ]
  
      constructor(date: Date, time: string, item: string, quantity: number, a: number) {
          this.meal_time = meal_time;
          this.date = date;
          this.time = time;
  
          this.ABC_Info[0].item = item;
          this.ABC_Info[0].quantity = quantity;
          this.ABC_Info[0].carbs = a;
  
          this.ABC_Info[1].item = item;
          this.ABC_Info[1].quantity = quantity;
          this.ABC_Info[1].carbs = a;
  
      }
  }
  </code></pre>
  
  <p><strong>abc.service.ts</strong></p>
  
  <pre><code>import { abc} from './models/abc';
  
  getABCs(start ? : moment.Moment, end ? : moment.Moment): Observable &lt; abc[] &gt; {
      let params = new HttpParams();
  
      if (start) {
          params = params.append('start', start.toISOString());
      }
  
      if (end) {
          params = params.append('end', end.toISOString());
      }
      return this.baseService.getParams('/api/abc/getAll', params)
          .pipe(
              map(res =&gt; res as Object[] || []),
              map(bolus =&gt; bolus.map(k =&gt; new abc(
                      new Date(k['date']),
                      k['time'],
                      k['item'],
                      k['quantity'],
                      k['a']))
  
              )
          )
  }
  </code></pre>
  
  <p><strong>Error in browser console</strong></p>
  
  <blockquote>
    <p>ERROR TypeError: Cannot read property '0' of undefined at new
    Bolus(abc.ts: 39) at abc.service.ts: 33 at Array.map( &lt; anonymous > )
    at MapSubscriber.project(carb.service.ts: 33) at MapSubscriber.push..
    / node_modules / rxjs / _esm5 / internal / operators /
    map.js.MapSubscriber._next(map.js: 35) at MapSubscriber.push.. /
    node_modules / rxjs / _esm5 / internal /
    Subscriber.js.Subscriber.next(Subscriber.js: 54) at
    MapSubscriber.push.. / node_modules / rxjs / _esm5 / internal /
    operators / map.js.MapSubscriber._next(map.js: 41) at
    MapSubscriber.push.. / node_modules / rxjs / _esm5 / internal /
    Subscriber.js.Subscriber.next(Subscriber.js: 54) at
    MergeMapSubscriber.push.. / node_modules / rxjs / _esm5 / internal /
    operators / mergeMap.js.MergeMapSubscriber.notifyNext(mergeMap.js: 84)
    at InnerSubscriber.push.. / node_modules / rxjs / _esm5 / internal /
    InnerSubscriber.js.InnerSubscriber._next(InnerSubscriber.js: 15)</p>
  </blockquote>