title: Cannot read property 'length' of undefined - Angular 7
body: <p>trying to get a picture link of the object. These objects are in the array and the method in typescript looks like this:</p>
  
  <pre><code>getMealPicture(orderLineMeal: OrderLine): string {
      for (let meal of this.meals) {
        if (meal.id === orderLineMeal.mealId) {
          return meal.picture;
        }
      }
    }
  </code></pre>
  
  <p>returns string and this string is put in HTML:</p>
  
  <pre><code>&lt;img src="{{getMealPicture(orderLineMeal)}}" alt="" class="cartMeal-picture"&gt;
  </code></pre>
  
  <p>And I'm getting this error:</p>
  
  <pre><code>ERROR TypeError: Cannot read property 'length' of undefined
  at CheckoutPageComponent.push../src/app/checkout-page/checkout-page.component.ts.CheckoutPageComponent.getMealPicture (checkout-page.component.ts:113)
  at Object.eval [as updateRenderer] (CheckoutPageComponent.html:9)
  at Object.debugUpdateRenderer [as updateRenderer] (core.js:22482)
  at checkAndUpdateView (core.js:21857)
  at callViewAction (core.js:22093)
  at execEmbeddedViewsAction (core.js:22056)
  at checkAndUpdateView (core.js:21853)
  at callViewAction (core.js:22093)
  at execComponentViewsAction (core.js:22035)
  at checkAndUpdateView (core.js:21858)
  </code></pre>
  
  <p>where the first row is pointing on row 113 where this HTML img tag is.
  But images are there, they will just sometimes load second-two after the content is loaded. Do you think it is the problem? </p>
  
  <p>this array of meals (this.meals) is taken from the service and backend .NET. So I initialized this array in constructor:</p>
  
  <pre><code>meals: Meal[];
  
  this.mealService.getAllMeals().subscribe( listOfMeals =&gt; {
    this.meals = listOfMeals;
  });
  </code></pre>
  
  <p>I tried everything but I wasn't able to solve this console error even though this error does not affect anything. I have a different amount of them each time I reload page. it is 2-4 usually. </p>
  
  <p>I thought that it is because img src is not loaded immediately, it takes some time so I put an array init in constructor but still error.</p>
  
  <p>Any thoughts? Tips? Thank you!</p>