title: Bind data from API to Dropdown in Angular 7
body: <p>I'm trying to populate a dropdown from a get API. I've created a service and using the observables returning the data to the component, which then subscribes to the service.
  I'm able to console.log the whole data (which is in a JSON array) but I'm not able to see any data in the dropdown.</p>
  
  <p>I guess the problem is that view is getting rendered before the API data. I know there is a resolve method but what else I can try?</p>
  
  <p>My question and code are very much similar to the below question and there are few things which I've already correct in my code like 'Project' is an array but the solution isn't working for me. There is no error in my code also:</p>
  
  <p><a href="https://stackoverflow.com/questions/53738984/drop-down-does-not-populate-with-api-data-in-angular">Drop down does not populate with API data in Angular</a></p>
  
  <p>Please find my code below:
  <strong>TestService.ts</strong></p>
  
  <pre><code>export class TestService {
    public testURL = 'https://test.url';
    constructor(private _http: HttpClient) { }
  
      getTypes(): Observable&lt;TestModel[]&gt; {
      const headers = new HttpHeaders({'test': 'test1'});
      return this._http.get&lt;TestModel[]&gt;(this.testURL, {headers});
    }
    }
  </code></pre>
  
  <p><strong>Component.ts</strong></p>
  
  <pre><code> @Component({
    selector: 'app-header',
    templateUrl: './app-header.component.html',
    styleUrls: ['./app-header.component.css']
  })
  export class AppHeaderComponent implements OnInit, AfterViewInit {
     testModel: TestModel[];
     isLoaded = false;
  
    constructor(private _testService: TestService) { }
  
    getTypeT(): void {
      this._testService.getTypes().subscribe(data =&gt; {
        if(data) {
          this.testModel = data;
          this.isLoaded = true;
          console.log(this.testModel);
        }
      } );
    }
  
    ngOnInit() {
      // fetch all the survey types
      this.getTypeT();
    }
  </code></pre>
  
  <p><strong>component.html</strong></p>
  
  <pre><code>  &lt;select  class="selectpicker dropdown mt-4 ml-3" id="type" data-live-search="true"&gt;
        &lt;option *ngFor="let test of testModel" [value]="test.id"&gt;{{test.description}}&lt;/option&gt;
     &lt;/select&gt;
  </code></pre>
  
  <p><strong>Note</strong>: I just figured out that problem seems to be with the "<strong>selectpicker</strong>" dropdown which is a third party plugin. Could you please suggest what I can do to resolve it?</p>