title: Cannot read property 'indexOf' of undefined in Angular
body: <p>I got this error in run time. These are code snippets of my code. I'm running Angular 9.</p>
  
  <pre><code>core.js:6237 ERROR TypeError: Cannot read property 'indexOf' of undefined
      at DishdetailComponent.setPrevNext (dishdetail.component.ts:31)
      at SafeSubscriber._next (dishdetail.component.ts:26)
      at SafeSubscriber.__tryOrUnsub (Subscriber.js:183)
      at SafeSubscriber.next (Subscriber.js:122)
      at Subscriber._next (Subscriber.js:72)
      at Subscriber.next (Subscriber.js:49)
      at SwitchMapSubscriber.notifyNext (switchMap.js:70)
      at InnerSubscriber._next (InnerSubscriber.js:11)
      at InnerSubscriber.next (Subscriber.js:49)
      at Notification.observe (Notification.js:20)
  </code></pre>
  
  <p>This is my dishdetail.component.ts file.</p>
  
  <pre><code>dish: Dish;
    dishIds : string[];
    prev: string;
    next: string;
  
    constructor(private dishService: DishService, private route: ActivatedRoute, private location: Location) { }
  
    ngOnInit(): void {
      this.dishService.getDishIds().subscribe(dishIds =&gt; this.dishIds);
      this.route.params.pipe(switchMap((params: Params) =&gt; this.dishService.getDish(params['id']))).
      subscribe(dish =&gt; {this.dish=dish; this.setPrevNext(dish.id)});
    }
  
    setPrevNext(dishId: string){
      console.log(dishId);
      const index = this.dishIds.indexOf(dishId);
      this.prev = this.dishIds[(this.dishIds.length + index -1) % this.dishIds.length];
      this.next = this.dishIds[(this.dishIds.length+ index +1) % this.dishIds.length];
    }
  
    goBack(): void {
      this.location.back();
    }
  </code></pre>
  
  <p><code>dishIds : string[]</code> is an array that contains string type id s of dishes. I need to iterate through the indexes of the array, then I implemented the setPrevNext method. And When run on the browser, it shows the above error. Please Help me. The browser shows the error is in 'indexof' in setPrevNext method.</p>