@@ -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 ,
@@ -142,13 +141,11 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
142
141
/** Whether animations for the chip are enabled. */
143
142
_animationsDisabled : boolean ;
144
143
145
- // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
146
- // In Ivy the `host` bindings will be merged when this class is extended, whereas in
147
- // ViewEngine they're overwritten.
148
- // TODO(mmalerba): we move this back into `host` once Ivy is turned on by default.
149
- // tslint:disable-next-line:no-host-decorator-in-concrete
150
- @HostListener ( 'transitionend' , [ '$event' ] )
151
- _handleTransitionEnd ( event : TransitionEvent ) {
144
+ /**
145
+ * Event listener for `transitionend` events. Needs to be an arrow
146
+ * function so we can pass it easily into `addEventListener`.
147
+ */
148
+ private _handleTransitionEnd = ( event : TransitionEvent ) => {
152
149
this . _chipFoundation . handleTransitionEnd ( event ) ;
153
150
}
154
151
@@ -311,7 +308,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
311
308
312
309
constructor (
313
310
public _changeDetectorRef : ChangeDetectorRef ,
314
- readonly _elementRef : ElementRef ,
311
+ readonly _elementRef : ElementRef < HTMLElement > ,
315
312
protected _ngZone : NgZone ,
316
313
@Optional ( ) private _dir : Directionality ,
317
314
// @breaking -change 8.0.0 `animationMode` parameter to become required.
@@ -322,6 +319,9 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
322
319
this . _isBasicChip = _elementRef . nativeElement . hasAttribute ( this . basicChipAttrName ) ||
323
320
_elementRef . nativeElement . tagName . toLowerCase ( ) === this . basicChipAttrName ;
324
321
322
+ _ngZone . runOutsideAngular ( ( ) => {
323
+ _elementRef . nativeElement . addEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
324
+ } ) ;
325
325
}
326
326
327
327
ngAfterContentInit ( ) {
@@ -336,6 +336,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
336
336
this . destroyed . emit ( { chip : this } ) ;
337
337
this . _destroyed . next ( ) ;
338
338
this . _destroyed . complete ( ) ;
339
+ this . _elementRef . nativeElement . removeEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
339
340
this . _chipFoundation . destroy ( ) ;
340
341
}
341
342
0 commit comments