@@ -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
@@ -312,7 +309,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
312
309
313
310
constructor (
314
311
public _changeDetectorRef : ChangeDetectorRef ,
315
- readonly _elementRef : ElementRef ,
312
+ readonly _elementRef : ElementRef < HTMLElement > ,
316
313
protected _ngZone : NgZone ,
317
314
@Optional ( ) private _dir : Directionality ,
318
315
// @breaking -change 8.0.0 `animationMode` parameter to become required.
@@ -322,6 +319,10 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
322
319
this . _animationsDisabled = animationMode === 'NoopAnimations' ;
323
320
this . _isBasicChip = _elementRef . nativeElement . hasAttribute ( this . basicChipAttrName ) ||
324
321
_elementRef . nativeElement . tagName . toLowerCase ( ) === this . basicChipAttrName ;
322
+
323
+ _ngZone . runOutsideAngular ( ( ) => {
324
+ _elementRef . nativeElement . addEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
325
+ } ) ;
325
326
}
326
327
327
328
ngAfterContentInit ( ) {
@@ -330,13 +331,15 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
330
331
331
332
ngAfterViewInit ( ) {
332
333
this . _chipFoundation . init ( ) ;
333
- this . _textElement = this . _elementRef . nativeElement . querySelector ( '.mdc-chip__text' ) ;
334
+ this . _textElement =
335
+ this . _elementRef . nativeElement . querySelector ( '.mdc-chip__text' ) as HTMLElement ;
334
336
}
335
337
336
338
ngOnDestroy ( ) {
337
339
this . destroyed . emit ( { chip : this } ) ;
338
340
this . _destroyed . next ( ) ;
339
341
this . _destroyed . complete ( ) ;
342
+ this . _elementRef . nativeElement . removeEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
340
343
this . _chipFoundation . destroy ( ) ;
341
344
}
342
345
0 commit comments