@@ -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 ,
@@ -143,13 +142,11 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
143
142
/** Whether animations for the chip are enabled. */
144
143
_animationsDisabled : boolean ;
145
144
146
- // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
147
- // In Ivy the `host` bindings will be merged when this class is extended, whereas in
148
- // ViewEngine they're overwritten.
149
- // TODO(mmalerba): we move this back into `host` once Ivy is turned on by default.
150
- // tslint:disable-next-line:no-host-decorator-in-concrete
151
- @HostListener ( 'transitionend' , [ '$event' ] )
152
- _handleTransitionEnd ( event : TransitionEvent ) {
145
+ /**
146
+ * Event listener for `transitionend` events. Needs to be an arrow
147
+ * function so we can pass it easily into `addEventListener`.
148
+ */
149
+ private _handleTransitionEnd = ( event : TransitionEvent ) => {
153
150
this . _chipFoundation . handleTransitionEnd ( event ) ;
154
151
}
155
152
@@ -340,6 +337,9 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
340
337
this . _animationsDisabled = animationMode === 'NoopAnimations' ;
341
338
this . _isBasicChip = elementRef . nativeElement . hasAttribute ( this . basicChipAttrName ) ||
342
339
elementRef . nativeElement . tagName . toLowerCase ( ) === this . basicChipAttrName ;
340
+ _ngZone . runOutsideAngular ( ( ) => {
341
+ elementRef . nativeElement . addEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
342
+ } ) ;
343
343
}
344
344
345
345
ngAfterContentInit ( ) {
@@ -348,11 +348,14 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
348
348
349
349
ngAfterViewInit ( ) {
350
350
this . _chipFoundation . init ( ) ;
351
- this . _textElement = this . _elementRef . nativeElement . querySelector ( '.mdc-chip__text' ) ;
351
+ this . _textElement =
352
+ this . _elementRef . nativeElement . querySelector ( '.mdc-chip__text' ) as HTMLElement ;
352
353
}
353
354
354
355
ngOnDestroy ( ) {
355
356
this . destroyed . emit ( { chip : this } ) ;
357
+ this . destroyed . complete ( ) ;
358
+ this . _elementRef . nativeElement . removeEventListener ( 'transitionend' , this . _handleTransitionEnd ) ;
356
359
this . _chipFoundation . destroy ( ) ;
357
360
}
358
361
0 commit comments