title: Unable to set selected value in ng-select right after the items data changes, but it works on the second try. Reactive Forms
body: <p>I am using ng-select with reactive forms and Angular 8.</p>
  <p>In my html file, I have the following:</p>
  <pre><code>&lt;ng-select #ngSelect [items]=&quot;tickets&quot;
                      [searchable]=&quot;true&quot;
                      bindLabel=&quot;myLabel&quot;
                      formControlName=&quot;ticketnum&quot;
                      placeholder=&quot;Select Ticket&quot;
                      [addTag]=&quot;true&quot;&gt;
                  &lt;/ng-select&gt;
  </code></pre>
  <p>I used addTag = true because I want the user to be able to use a value that's not in the list</p>
  <p>The tickets array (an array of objects) changes dynamically based on the value of another form control 'X'. When the value of 'X' changes (i.e. if a user selects a different value), tickets gets set to a different array of objects.</p>
  <p>All of that works fine, but the problem is that when the page loads, based on the URL I am programmatically setting the value for the 'X' control like this:</p>
  <pre><code>myFormGroup.controls['X'].setValue(thevalue); 
  </code></pre>
  <p>I noticed that the (change) event for the X control does not fire, maybe because I'm only changing the value, but not actually touching it in the UI? So I called the change function directly to assign tickets to a new array.</p>
  <p>All of that works too, I can watch it in chrome debugger. But the next thing I need to do is set the selected item of the ng-select, based on another URL variable. But when I go to do that, items is empty..so when I try to select a particular item, it doesn't work. I'm using this code to select it:</p>
  <pre><code>@ViewChild (NgSelectComponent, { static: true }) ngSelect: NgSelectComponent;
  
  let item = this.ngSelect.itemsList.findByLabel(thelabel);
  if (typeof item !== 'undefined') {
      this.ngSelect.select(item);
      myFormGroup.controls['ticketnum'].setValue(item.value);
  }
  </code></pre>
  <p>The item is not found - it's undefined. But then if I click on the dropdown with the mouse, [items] gets populated (and I see the items are displayed in the ng-select control). Then if I try a second time to select a particular item using the same code above, the item is found and it works...I see it selected in the control. But if I change 'X' again, the first time I try to select an item it fails and second time succeeds.</p>
  <p>How do I get it working the first time???</p>
  <p>Maybe it's taking time for the control to load after I set the value of tickets and the select is trying to select the item before it loads? But even when tickets only has 2 items (fast to load) it isn't working.</p>
  <p>Also, I don't know if static: true is correct for @ViewChild</p>
  <p>Thanks for any help on this.</p>