@@ -24,7 +24,7 @@ describe('MdAutocomplete', () => {
24
24
imports : [
25
25
MdAutocompleteModule . forRoot ( ) , MdInputModule . forRoot ( ) , ReactiveFormsModule
26
26
] ,
27
- declarations : [ SimpleAutocomplete ] ,
27
+ declarations : [ SimpleAutocomplete , AutocompleteWithoutForms ] ,
28
28
providers : [
29
29
{ provide : OverlayContainer , useFactory : ( ) => {
30
30
overlayContainerElement = document . createElement ( 'div' ) ;
@@ -790,6 +790,25 @@ describe('MdAutocomplete', () => {
790
790
791
791
} ) ;
792
792
793
+ describe ( 'misc' , ( ) => {
794
+
795
+ it ( 'should allow basic use without any forms directives' , ( ) => {
796
+ expect ( ( ) => {
797
+ const fixture = TestBed . createComponent ( AutocompleteWithoutForms ) ;
798
+ fixture . detectChanges ( ) ;
799
+
800
+ const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
801
+ input . value = 'd' ;
802
+ dispatchEvent ( 'input' , input ) ;
803
+ fixture . detectChanges ( ) ;
804
+
805
+ const options =
806
+ overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
807
+ expect ( options . length ) . toBe ( 1 ) ;
808
+ } ) . not . toThrowError ( ) ;
809
+ } ) ;
810
+
811
+ } ) ;
793
812
} ) ;
794
813
795
814
@Component ( {
@@ -849,6 +868,33 @@ class SimpleAutocomplete implements OnDestroy {
849
868
}
850
869
851
870
871
+ @Component ( {
872
+ template : `
873
+ <md-input-container>
874
+ <input mdInput placeholder="State" [mdAutocomplete]="auto"
875
+ (input)="onInput($event.target?.value)">
876
+ </md-input-container>
877
+
878
+ <md-autocomplete #auto="mdAutocomplete">
879
+ <md-option *ngFor="let state of filteredStates" [value]="state">
880
+ <span> {{ state }} </span>
881
+ </md-option>
882
+ </md-autocomplete>
883
+ `
884
+ } )
885
+ class AutocompleteWithoutForms {
886
+ filteredStates : any [ ] ;
887
+ states = [ 'Alabama' , 'California' , 'Florida' ] ;
888
+
889
+ constructor ( ) {
890
+ this . filteredStates = this . states . slice ( ) ;
891
+ }
892
+
893
+ onInput ( value : any ) {
894
+ this . filteredStates = this . states . filter ( s => new RegExp ( value , 'gi' ) . test ( s ) ) ;
895
+ }
896
+
897
+ }
852
898
853
899
/**
854
900
* TODO: Move this to core testing utility until Angular has event faking
0 commit comments