Search code examples
angulartypeaheadng2-bootstrap

Getting an error "TypeError: undefined is not observable"


I'm using angular2 and ng2-bootstrap.

My typeahead is setup as follows:

<input [(ngModel)]="selectedAsset"
               [typeahead]="assets"
               (typeaheadOnSelect)="typeaheadOnSelect($event)"
               class="form-control">

As soon as I type in the input box I get this error:

typeahead.directive.js:189 TypeError: undefined is not observable

Solution

  • After lots of searching and reading I eventually found the problem.

    The name of the assets list in my typescript file was different to the html

    private assets: Array<string> = [];
    private selectedAsset: string='';
    

    As long as those two are in the component.ts file (and are correctly spelt) it all works brilliantly.