@@ -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
@@ -334,7 +331,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
334
331
335
332
constructor (
336
333
public _changeDetectorRef : ChangeDetectorRef ,
337
- readonly _elementRef : ElementRef , protected _ngZone : NgZone ,
334
+ readonly _elementRef : ElementRef < HTMLElement > , protected _ngZone : NgZone ,
338
335
@Optional ( ) private _dir : Directionality ,
339
336
// @breaking -change 8.0.0 `animationMode` parameter to become required.
340
337
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ) {
@@ -343,6 +340,10 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
343
340
this . _animationsDisabled = animationMode === 'NoopAnimations' ;
344
341
this . _isBasicChip = _elementRef . nativeElement . hasAttribute ( this . basicChipAttrName ) ||
345
342
_elementRef . nativeElement . tagName . toLowerCase ( ) === this . basicChipAttrName ;
343
+
344
+ _ngZone . runOutsideAngular ( ( ) => {
345
+ _elementRef . nativeElement . addEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
346
+ } ) ;
346
347
}
347
348
348
349
ngAfterContentInit ( ) {
@@ -351,13 +352,15 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
351
352
352
353
ngAfterViewInit ( ) {
353
354
this . _chipFoundation . init ( ) ;
354
- this . _textElement = this . _elementRef . nativeElement . querySelector ( '.mdc-chip__text' ) ;
355
+ this . _textElement =
356
+ this . _elementRef . nativeElement . querySelector ( '.mdc-chip__text' ) as HTMLElement ;
355
357
}
356
358
357
359
ngOnDestroy ( ) {
358
360
this . destroyed . emit ( { chip : this } ) ;
359
361
this . _destroyed . next ( ) ;
360
362
this . _destroyed . complete ( ) ;
363
+ this . _elementRef . nativeElement . removeEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
361
364
this . _chipFoundation . destroy ( ) ;
362
365
}
363
366
0 commit comments