diff --git a/src/spec/typeahead.directive.spec.ts b/src/spec/typeahead.directive.spec.ts index 91e400290c..55a97899af 100644 --- a/src/spec/typeahead.directive.spec.ts +++ b/src/spec/typeahead.directive.spec.ts @@ -185,6 +185,19 @@ describe('Directive: Typeahead', () => { expect(fixture.debugElement.query(By.css('typeahead-container'))).toBeNull(); }) ); + + it('should not throw an error on blur', fakeAsync(() => { + expect(directive._container).toBeFalsy(); + expect(directive.matches).toEqual([]); + + dispatchMouseEvent(inputElement, 'click'); + tick(); + fixture.detectChanges(); + + fixture.whenStable().then(() => { + expect(() => directive.onBlur()).not.toThrowError(); + }); + })); }); describe('onFocus', () => { diff --git a/src/typeahead/typeahead.directive.ts b/src/typeahead/typeahead.directive.ts index a13852e2af..4bb19585b3 100644 --- a/src/typeahead/typeahead.directive.ts +++ b/src/typeahead/typeahead.directive.ts @@ -159,7 +159,7 @@ export class TypeaheadDirective implements OnInit, OnDestroy { // tslint:disable-next-line:no-any protected keyUpEventEmitter: EventEmitter = new EventEmitter(); - protected _matches: TypeaheadMatch[]; + protected _matches: TypeaheadMatch[] = []; protected placement = 'bottom left'; private _typeahead: ComponentLoader;