@@ -24,6 +24,7 @@ import { fromEvent, Observable, Subscription, of } from 'rxjs';
2424import { map , filter , debounceTime , switchMap , tap } from 'rxjs/operators' ;
2525import { PositionService } from 'ng-devui/position' ;
2626import { AutoCompletePopupComponent } from './auto-complete-popup.component' ;
27+ import { AutoCompleteConfig } from './auto-complete-config' ;
2728
2829@Directive ( {
2930 selector : '[dAutoComplete]' ,
@@ -80,20 +81,22 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
8081 private onChange = ( _ : any ) => null ;
8182 private onTouched = ( ) => null ;
8283
83- constructor ( private elementRef : ElementRef ,
84+ constructor (
85+ private autoCompleteConfig : AutoCompleteConfig ,
86+ private elementRef : ElementRef ,
8487 private viewContainerRef : ViewContainerRef ,
8588 private componentFactoryResolver : ComponentFactoryResolver ,
8689 private renderer : Renderer2 ,
8790 private injector : Injector ,
8891 private positionService : PositionService ,
8992 private changeDetectorRef : ChangeDetectorRef ) {
90- this . delay = 300 ;
93+ this . delay = this . autoCompleteConfig . autoComplete . delay ;
9194 this . valueChanges = this . registerInputEvent ( elementRef ) ;
92- this . minLength = 1 ;
93- this . itemTemplate = null ;
94- this . noResultItemTemplate = null ;
95- this . formatter = ( item : any ) => item ? ( item . label || item . toString ( ) ) : '' ;
96- this . valueParser = ( item : any ) => item ;
95+ this . minLength = this . autoCompleteConfig . autoComplete . minLength ;
96+ this . itemTemplate = this . autoCompleteConfig . autoComplete . itemTemplate ;
97+ this . noResultItemTemplate = this . autoCompleteConfig . autoComplete . noResultItemTemplate ;
98+ this . formatter = this . autoCompleteConfig . autoComplete . formatter ;
99+ this . valueParser = this . autoCompleteConfig . autoComplete . valueParser ;
97100 }
98101
99102 ngOnInit ( ) {
@@ -147,7 +150,7 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
147150 }
148151
149152 // 调用时机:input keyup
150- onSourceChange ( source : any ) {
153+ onSourceChange ( source ) {
151154 if ( ! this . elementRef . nativeElement . value ) {
152155 if ( this . sceneType !== 'select' ) { // 下拉场景不展示最近输入
153156 this . showLatestSource ( ) ;
@@ -186,7 +189,7 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
186189 }
187190 }
188191
189- private showSource ( source : any , setOpen : any , isReset : any ) {
192+ private showSource ( source , setOpen , isReset ) {
190193 if ( ( source && source . length ) || this . noResultItemTemplate ) {
191194 const pop = this . popupRef . instance ;
192195 if ( isReset ) {
@@ -203,16 +206,16 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
203206 }
204207 }
205208
206- writeValue ( obj : any ) : void {
209+ writeValue ( obj ) : void {
207210 this . value = this . formatter ( obj ) || '' ;
208211 this . writeInputValue ( this . value ) ;
209212 }
210213
211- registerOnChange ( fn : any ) : void {
214+ registerOnChange ( fn ) : void {
212215 this . onChange = fn ;
213216 }
214217
215- registerOnTouched ( fn : any ) : void {
218+ registerOnTouched ( fn ) : void {
216219 this . onTouched = fn ;
217220 }
218221
@@ -229,7 +232,7 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
229232 }
230233
231234 @HostListener ( 'focus' , [ '$event' ] )
232- onFocus ( $event : any ) {
235+ onFocus ( $event ) {
233236 this . focus = true ;
234237 this . transInputFocusEmit . emit ( {
235238 focus : true ,
@@ -252,18 +255,18 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
252255 }
253256
254257 @HostListener ( 'blur' , [ '$event' ] )
255- onBlur ( $event : any ) {
258+ onBlur ( $event ) {
256259 this . focus = false ;
257260 this . onTouched ( ) ;
258261 }
259262
260263 @HostListener ( 'keydown.esc' , [ '$event' ] )
261- onEscKeyup ( $event : any ) {
264+ onEscKeyup ( $event ) {
262265 this . hidePopup ( ) ;
263266 }
264267
265268 @HostListener ( 'keydown.Enter' , [ '$event' ] )
266- onEnterKeyDown ( $event : any ) {
269+ onEnterKeyDown ( $event ) {
267270 if ( ! this . popupRef . instance . source || ! this . popupRef . instance . isOpen ) {
268271 return ;
269272 }
@@ -273,7 +276,7 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
273276 }
274277
275278 @HostListener ( 'keydown.ArrowUp' , [ '$event' ] )
276- onArrowUpKeyDown ( $event : any ) {
279+ onArrowUpKeyDown ( $event ) {
277280 if ( this . popupRef ) {
278281 $event . preventDefault ( ) ;
279282 $event . stopPropagation ( ) ;
@@ -282,7 +285,7 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
282285 }
283286
284287 @HostListener ( 'keydown.ArrowDown' , [ '$event' ] )
285- onArrowDownKeyDown ( $event : any ) {
288+ onArrowDownKeyDown ( $event ) {
286289 if ( this . popupRef ) {
287290 $event . preventDefault ( ) ;
288291 $event . stopPropagation ( ) ;
@@ -318,7 +321,7 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
318321 }
319322 }
320323
321- private fillPopup ( source ?: any , term ?: string ) {
324+ private fillPopup ( source ?, term ?: string ) {
322325 this . position = this . positionService . position ( this . elementRef . nativeElement ) ;
323326 const pop = this . popupRef . instance ;
324327 pop . source = source ;
@@ -334,7 +337,7 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
334337 } ) ;
335338 }
336339
337- private writeInputValue ( value : any ) {
340+ private writeInputValue ( value ) {
338341 this . renderer . setProperty ( this . elementRef . nativeElement , 'value' , value ) ;
339342 }
340343
@@ -349,7 +352,7 @@ export class AutoCompleteDirective implements OnInit, OnDestroy, OnChanges, Cont
349352 }
350353 }
351354
352- onTermChange ( term : any ) {
355+ onTermChange ( term ) {
353356 this . value = term ;
354357 if ( this . popupRef ) {
355358 this . popupRef . instance . term = term ;
0 commit comments