@@ -26,7 +26,7 @@ import {
26
26
OnDestroy ,
27
27
Optional ,
28
28
Output ,
29
- ViewEncapsulation , HostListener
29
+ ViewEncapsulation ,
30
30
} from '@angular/core' ;
31
31
import {
32
32
CanColor ,
@@ -128,13 +128,11 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
128
128
/** Whether animations for the chip are enabled. */
129
129
_animationsDisabled : boolean ;
130
130
131
- // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
132
- // In Ivy the `host` bindings will be merged when this class is extended, whereas in
133
- // ViewEngine they're overwritten.
134
- // TODO(mmalerba): we move this back into `host` once Ivy is turned on by default.
135
- // tslint:disable-next-line:no-host-decorator-in-concrete
136
- @HostListener ( 'transitionend' , [ '$event' ] )
137
- _handleTransitionEnd ( event : TransitionEvent ) {
131
+ /**
132
+ * Event listener for `transitionend` events. Needs to be an arrow
133
+ * function so we can pass it easily into `addEventListener`.
134
+ */
135
+ private _handleTransitionEnd = ( event : TransitionEvent ) => {
138
136
this . _chipFoundation . handleTransitionEnd ( event ) ;
139
137
}
140
138
@@ -296,7 +294,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
296
294
297
295
constructor (
298
296
public _changeDetectorRef : ChangeDetectorRef ,
299
- readonly _elementRef : ElementRef ,
297
+ readonly _elementRef : ElementRef < HTMLElement > ,
300
298
private _platform : Platform ,
301
299
protected _ngZone : NgZone ,
302
300
@Optional ( ) @Inject ( MAT_RIPPLE_GLOBAL_OPTIONS )
@@ -307,6 +305,10 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
307
305
super ( _elementRef ) ;
308
306
this . _chipFoundation = new MDCChipFoundation ( this . _chipAdapter ) ;
309
307
this . _animationsDisabled = animationMode === 'NoopAnimations' ;
308
+
309
+ _ngZone . runOutsideAngular ( ( ) => {
310
+ _elementRef . nativeElement . addEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
311
+ } ) ;
310
312
}
311
313
312
314
ngAfterContentInit ( ) {
@@ -323,6 +325,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
323
325
this . _destroyed . next ( ) ;
324
326
this . _destroyed . complete ( ) ;
325
327
this . _rippleRenderer . _removeTriggerEvents ( ) ;
328
+ this . _elementRef . nativeElement . removeEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
326
329
this . _chipFoundation . destroy ( ) ;
327
330
}
328
331
0 commit comments