@@ -5,7 +5,7 @@ import {MdAutocompleteModule, MdAutocompleteTrigger} from './index';
55import { OverlayContainer } from '../core/overlay/overlay-container' ;
66import { MdInputModule } from '../input/index' ;
77import { Dir , LayoutDirection } from '../core/rtl/dir' ;
8- import { FormControl , ReactiveFormsModule } from '@angular/forms' ;
8+ import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
99import { Subscription } from 'rxjs/Subscription' ;
1010import { ENTER , DOWN_ARROW , SPACE , UP_ARROW } from '../core/keyboard/keycodes' ;
1111import { MdOption } from '../core/option/option' ;
@@ -26,9 +26,14 @@ describe('MdAutocomplete', () => {
2626 dir = 'ltr' ;
2727 TestBed . configureTestingModule ( {
2828 imports : [
29- MdAutocompleteModule . forRoot ( ) , MdInputModule . forRoot ( ) , ReactiveFormsModule
29+ MdAutocompleteModule . forRoot ( ) , MdInputModule . forRoot ( ) , FormsModule , ReactiveFormsModule
30+ ] ,
31+ declarations : [
32+ SimpleAutocomplete ,
33+ AutocompleteWithoutForms ,
34+ NgIfAutocomplete ,
35+ AutocompleteWithNgModel
3036 ] ,
31- declarations : [ SimpleAutocomplete , AutocompleteWithoutForms , NgIfAutocomplete ] ,
3237 providers : [
3338 { provide : OverlayContainer , useFactory : ( ) => {
3439 overlayContainerElement = document . createElement ( 'div' ) ;
@@ -863,6 +868,18 @@ describe('MdAutocomplete', () => {
863868 } ) . not . toThrowError ( ) ;
864869 } ) ;
865870
871+ it ( 'should display an empty input when the value is undefined with ngModel' , async ( ( ) => {
872+ const fixture = TestBed . createComponent ( AutocompleteWithNgModel ) ;
873+
874+ fixture . detectChanges ( ) ;
875+
876+ fixture . whenStable ( ) . then ( ( ) => {
877+ const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
878+
879+ expect ( input . value ) . toBe ( '' ) ;
880+ } ) ;
881+ } ) ) ;
882+
866883 it ( 'should work when input is wrapped in ngIf' , ( ) => {
867884 const fixture = TestBed . createComponent ( NgIfAutocomplete ) ;
868885 fixture . detectChanges ( ) ;
@@ -997,6 +1014,36 @@ class AutocompleteWithoutForms {
9971014
9981015}
9991016
1017+
1018+ @Component ( {
1019+ template : `
1020+ <md-input-container>
1021+ <input mdInput placeholder="State" [mdAutocomplete]="auto" [(ngModel)]="selectedState"
1022+ (ngModelChange)="onInput($event)">
1023+ </md-input-container>
1024+
1025+ <md-autocomplete #auto="mdAutocomplete">
1026+ <md-option *ngFor="let state of filteredStates" [value]="state">
1027+ <span>{{ state }}</span>
1028+ </md-option>
1029+ </md-autocomplete>
1030+ `
1031+ } )
1032+ class AutocompleteWithNgModel {
1033+ filteredStates : any [ ] ;
1034+ selectedState : string ;
1035+ states = [ 'New York' , 'Washington' , 'Oregon' ] ;
1036+
1037+ constructor ( ) {
1038+ this . filteredStates = this . states . slice ( ) ;
1039+ }
1040+
1041+ onInput ( value : any ) {
1042+ this . filteredStates = this . states . filter ( s => new RegExp ( value , 'gi' ) . test ( s ) ) ;
1043+ }
1044+
1045+ }
1046+
10001047/**
10011048 * Focuses an input, sets its value and dispatches
10021049 * the `input` event, simulating the user typing.
0 commit comments