@@ -136,13 +136,11 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
136
136
/** Whether animations for the chip are enabled. */
137
137
_animationsDisabled : boolean ;
138
138
139
- // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
140
- // In Ivy the `host` bindings will be merged when this class is extended, whereas in
141
- // ViewEngine they're overwritten.
142
- // TODO(mmalerba): we move this back into `host` once Ivy is turned on by default.
143
- // tslint:disable-next-line:no-host-decorator-in-concrete
144
- @HostListener ( 'transitionend' , [ '$event' ] )
145
- _handleTransitionEnd ( event : TransitionEvent ) {
139
+ /**
140
+ * Event listener for `transitionend` events. Needs to be an arrow
141
+ * function so we can pass it easily into `addEventListener`.
142
+ */
143
+ private _handleTransitionEnd = ( event : TransitionEvent ) => {
146
144
this . _chipFoundation . handleTransitionEnd ( event ) ;
147
145
}
148
146
@@ -305,14 +303,18 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
305
303
306
304
constructor (
307
305
public _changeDetectorRef : ChangeDetectorRef ,
308
- readonly _elementRef : ElementRef ,
306
+ readonly _elementRef : ElementRef < HTMLElement > ,
309
307
protected _ngZone : NgZone ,
310
308
@Optional ( ) private _dir : Directionality ,
311
309
// @breaking -change 8.0.0 `animationMode` parameter to become required.
312
310
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ) {
313
311
super ( _elementRef ) ;
314
312
this . _chipFoundation = new MDCChipFoundation ( this . _chipAdapter ) ;
315
313
this . _animationsDisabled = animationMode === 'NoopAnimations' ;
314
+
315
+ _ngZone . runOutsideAngular ( ( ) => {
316
+ _elementRef . nativeElement . addEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
317
+ } ) ;
316
318
}
317
319
318
320
ngAfterContentInit ( ) {
@@ -327,6 +329,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
327
329
this . destroyed . emit ( { chip : this } ) ;
328
330
this . _destroyed . next ( ) ;
329
331
this . _destroyed . complete ( ) ;
332
+ this . _elementRef . nativeElement . removeEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
330
333
this . _chipFoundation . destroy ( ) ;
331
334
}
332
335
0 commit comments