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