@@ -5,7 +5,7 @@ import {MdAutocompleteModule, MdAutocompleteTrigger} from './index';
5
5
import { OverlayContainer } from '../core/overlay/overlay-container' ;
6
6
import { MdInputModule } from '../input/index' ;
7
7
import { Dir , LayoutDirection } from '../core/rtl/dir' ;
8
- import { FormControl , ReactiveFormsModule } from '@angular/forms' ;
8
+ import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
9
9
import { Subscription } from 'rxjs/Subscription' ;
10
10
import { ENTER , DOWN_ARROW , SPACE , UP_ARROW } from '../core/keyboard/keycodes' ;
11
11
import { MdOption } from '../core/option/option' ;
@@ -26,9 +26,14 @@ describe('MdAutocomplete', () => {
26
26
dir = 'ltr' ;
27
27
TestBed . configureTestingModule ( {
28
28
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
30
36
] ,
31
- declarations : [ SimpleAutocomplete , AutocompleteWithoutForms , NgIfAutocomplete ] ,
32
37
providers : [
33
38
{ provide : OverlayContainer , useFactory : ( ) => {
34
39
overlayContainerElement = document . createElement ( 'div' ) ;
@@ -863,6 +868,18 @@ describe('MdAutocomplete', () => {
863
868
} ) . not . toThrowError ( ) ;
864
869
} ) ;
865
870
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
+
866
883
it ( 'should work when input is wrapped in ngIf' , ( ) => {
867
884
const fixture = TestBed . createComponent ( NgIfAutocomplete ) ;
868
885
fixture . detectChanges ( ) ;
@@ -997,6 +1014,36 @@ class AutocompleteWithoutForms {
997
1014
998
1015
}
999
1016
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
+
1000
1047
/**
1001
1048
* Focuses an input, sets its value and dispatches
1002
1049
* the `input` event, simulating the user typing.
0 commit comments