@@ -27,6 +27,7 @@ import {
27
27
ViewEncapsulation ,
28
28
} from '@angular/core' ;
29
29
import { CanColor , CanColorCtor , mixinColor } from '@angular/material/core' ;
30
+ import { Subscription } from 'rxjs' ;
30
31
import { take } from 'rxjs/operators' ;
31
32
32
33
import { MatIconRegistry } from './icon-registry' ;
@@ -178,6 +179,9 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
178
179
/** Keeps track of the elements and attributes that we've prefixed with the current path. */
179
180
private _elementsWithExternalReferences ?: Map < Element , { name : string , value : string } [ ] > ;
180
181
182
+ /** Subscription to the current in-progress SVG icon request. */
183
+ private _currentIconFetch = Subscription . EMPTY ;
184
+
181
185
constructor (
182
186
elementRef : ElementRef < HTMLElement > , private _iconRegistry : MatIconRegistry ,
183
187
@Attribute ( 'aria-hidden' ) ariaHidden : string ,
@@ -227,10 +231,12 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
227
231
const svgIconChanges = changes [ 'svgIcon' ] ;
228
232
229
233
if ( svgIconChanges ) {
234
+ this . _currentIconFetch . unsubscribe ( ) ;
235
+
230
236
if ( this . svgIcon ) {
231
237
const [ namespace , iconName ] = this . _splitIconName ( this . svgIcon ) ;
232
238
233
- this . _iconRegistry . getNamedSvgIcon ( iconName , namespace )
239
+ this . _currentIconFetch = this . _iconRegistry . getNamedSvgIcon ( iconName , namespace )
234
240
. pipe ( take ( 1 ) )
235
241
. subscribe ( svg => this . _setSvgElement ( svg ) , ( err : Error ) => {
236
242
const errorMessage = `Error retrieving icon ${ namespace } :${ iconName } ! ${ err . message } ` ;
@@ -279,6 +285,8 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
279
285
}
280
286
281
287
ngOnDestroy ( ) {
288
+ this . _currentIconFetch . unsubscribe ( ) ;
289
+
282
290
if ( this . _elementsWithExternalReferences ) {
283
291
this . _elementsWithExternalReferences . clear ( ) ;
284
292
}
0 commit comments