1- import { IgxInputDirective , IgxInputState } from './../directives/input/input.directive' ;
21import {
32 AfterContentInit ,
43 AfterViewInit ,
@@ -20,24 +19,27 @@ import {
2019 TemplateRef ,
2120 ViewChild
2221} from '@angular/core' ;
23- import { ControlValueAccessor , NG_VALUE_ACCESSOR , NgControl , AbstractControl } from '@angular/forms' ;
24- import { Subscription } from 'rxjs' ;
25-
26- import { IgxDropDownItemBaseDirective } from '../drop-down/public_api' ;
22+ import { AbstractControl , ControlValueAccessor , NgControl , NG_VALUE_ACCESSOR } from '@angular/forms' ;
23+ import { Subject } from 'rxjs' ;
24+ import { takeUntil } from 'rxjs/operators' ;
25+ import { DisplayDensityToken , IDisplayDensityOptions } from '../core/density' ;
26+ import { EditorProvider } from '../core/edit-provider' ;
27+ import { IgxSelectionAPIService } from '../core/selection' ;
28+ import { CancelableEventArgs } from '../core/utils' ;
29+ import { IgxLabelDirective } from '../directives/label/label.directive' ;
30+ import { IgxDropDownItemBaseDirective } from '../drop-down/drop-down-item.base' ;
31+ import { IGX_DROPDOWN_BASE , ISelectionEventArgs , Navigate } from '../drop-down/drop-down.common' ;
2732import { IgxInputGroupComponent } from '../input-group/input-group.component' ;
28-
33+ import { AbsoluteScrollStrategy } from '../services/overlay/scroll/absolute-scroll-strategy' ;
34+ import { OverlaySettings } from '../services/overlay/utilities' ;
35+ import { IgxInputDirective , IgxInputState } from './../directives/input/input.directive' ;
2936import { IgxDropDownComponent } from './../drop-down/drop-down.component' ;
3037import { IgxSelectItemComponent } from './select-item.component' ;
3138import { SelectPositioningStrategy } from './select-positioning-strategy' ;
32-
33- import { OverlaySettings , AbsoluteScrollStrategy } from '../services/public_api' ;
34- import { IGX_DROPDOWN_BASE , ISelectionEventArgs , Navigate } from '../drop-down/drop-down.common' ;
35- import { CancelableEventArgs } from '../core/utils' ;
36- import { IgxLabelDirective } from '../directives/label/label.directive' ;
3739import { IgxSelectBase } from './select.common' ;
38- import { EditorProvider } from '../core/edit-provider' ;
39- import { IgxSelectionAPIService } from '../core/selection' ;
40- import { DisplayDensityToken , IDisplayDensityOptions } from '../core/density' ;
40+
41+
42+
4143
4244/** @hidden @internal */
4345@Directive ( {
@@ -94,9 +96,9 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
9496 AfterContentInit , OnInit , AfterViewInit , OnDestroy , EditorProvider {
9597
9698 private ngControl : NgControl = null ;
97- private _statusChanges$ : Subscription ;
9899 private _overlayDefaults : OverlaySettings ;
99100 private _value : any ;
101+ protected destroy$ = new Subject < boolean > ( ) ;
100102
101103 /** @hidden @internal do not use the drop-down container class */
102104 public cssClass = false ;
@@ -365,11 +367,15 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
365367 scrollStrategy : new AbsoluteScrollStrategy ( ) ,
366368 excludePositionTarget : true
367369 } ;
368- this . children . changes . subscribe ( ( ) => {
370+ const changes$ = this . children . changes . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( ( ) => {
369371 this . setSelection ( this . items . find ( x => x . value === this . value ) ) ;
370372 this . cdr . detectChanges ( ) ;
371373 } ) ;
372- Promise . resolve ( ) . then ( ( ) => this . children . notifyOnChanges ( ) ) ;
374+ Promise . resolve ( ) . then ( ( ) => {
375+ if ( ! changes$ . closed ) {
376+ this . children . notifyOnChanges ( ) ;
377+ }
378+ } ) ;
373379 }
374380
375381 /** @hidden @internal */
@@ -408,7 +414,7 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
408414 public onBlur ( ) : void {
409415 this . _onTouchedCallback ( ) ;
410416 if ( this . ngControl && ! this . ngControl . valid ) {
411- this . input . valid = IgxInputState . INVALID ;
417+ this . input . valid = IgxInputState . INVALID ;
412418 } else {
413419 this . input . valid = IgxInputState . INITIAL ;
414420 }
@@ -445,7 +451,7 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
445451 */
446452 public ngAfterViewInit ( ) {
447453 if ( this . ngControl ) {
448- this . _statusChanges$ = this . ngControl . statusChanges . subscribe ( this . onStatusChanged . bind ( this ) ) ;
454+ this . ngControl . statusChanges . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( this . onStatusChanged . bind ( this ) ) ;
449455 this . manageRequiredAsterisk ( ) ;
450456 }
451457 this . cdr . detectChanges ( ) ;
@@ -455,17 +461,16 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
455461 * @hidden @internal
456462 */
457463 public ngOnDestroy ( ) {
464+ this . destroy$ . next ( true ) ;
465+ this . destroy$ . complete ( ) ;
458466 this . selection . clear ( this . id ) ;
459- if ( this . _statusChanges$ ) {
460- this . _statusChanges$ . unsubscribe ( ) ;
461- }
462467 }
463468
464469 /**
465470 * @hidden @internal
466471 * Prevent input blur - closing the items container on Header/Footer Template click.
467472 */
468- public mousedownHandler ( event ) {
473+ public mousedownHandler ( event ) {
469474 event . preventDefault ( ) ;
470475 }
471476}
0 commit comments