@@ -19,7 +19,6 @@ import {
19
19
Directive ,
20
20
ElementRef ,
21
21
EventEmitter ,
22
- HostListener ,
23
22
Inject ,
24
23
Input ,
25
24
NgZone ,
@@ -151,13 +150,11 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
151
150
/** Whether animations for the chip are enabled. */
152
151
_animationsDisabled : boolean ;
153
152
154
- // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
155
- // In Ivy the `host` bindings will be merged when this class is extended, whereas in
156
- // ViewEngine they're overwritten.
157
- // TODO(mmalerba): we move this back into `host` once Ivy is turned on by default.
158
- // tslint:disable-next-line:no-host-decorator-in-concrete
159
- @HostListener ( 'transitionend' , [ '$event' ] )
160
- _handleTransitionEnd ( event : TransitionEvent ) {
153
+ /**
154
+ * Event listener for `transitionend` events. Needs to be an arrow
155
+ * function so we can pass it easily into `addEventListener`.
156
+ */
157
+ private _handleTransitionEnd = ( event : TransitionEvent ) => {
161
158
this . _chipFoundation . handleTransitionEnd ( event ) ;
162
159
}
163
160
@@ -338,7 +335,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
338
335
339
336
constructor (
340
337
public _changeDetectorRef : ChangeDetectorRef ,
341
- readonly _elementRef : ElementRef , protected _ngZone : NgZone ,
338
+ readonly _elementRef : ElementRef < HTMLElement > , protected _ngZone : NgZone ,
342
339
@Optional ( ) private _dir : Directionality ,
343
340
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ,
344
341
@Optional ( ) @Inject ( MAT_RIPPLE_GLOBAL_OPTIONS )
@@ -348,6 +345,10 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
348
345
this . _animationsDisabled = animationMode === 'NoopAnimations' ;
349
346
this . _isBasicChip = _elementRef . nativeElement . hasAttribute ( this . basicChipAttrName ) ||
350
347
_elementRef . nativeElement . tagName . toLowerCase ( ) === this . basicChipAttrName ;
348
+
349
+ _ngZone . runOutsideAngular ( ( ) => {
350
+ _elementRef . nativeElement . addEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
351
+ } ) ;
351
352
}
352
353
353
354
ngAfterContentInit ( ) {
@@ -356,11 +357,14 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
356
357
357
358
ngAfterViewInit ( ) {
358
359
this . _chipFoundation . init ( ) ;
359
- this . _textElement = this . _elementRef . nativeElement . querySelector ( '.mdc-chip__text' ) ;
360
+ this . _textElement =
361
+ this . _elementRef . nativeElement . querySelector ( '.mdc-chip__text' ) as HTMLElement ;
360
362
}
361
363
362
364
ngOnDestroy ( ) {
363
365
this . destroyed . emit ( { chip : this } ) ;
366
+ this . destroyed . complete ( ) ;
367
+ this . _elementRef . nativeElement . removeEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
364
368
this . _chipFoundation . destroy ( ) ;
365
369
}
366
370
0 commit comments