|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {take} from 'rxjs/operators'; |
| 9 | +import {coerceBooleanProperty} from '@angular/cdk/coercion'; |
| 10 | +import {DOCUMENT} from '@angular/common'; |
10 | 11 | import {
|
| 12 | + AfterViewChecked, |
11 | 13 | Attribute,
|
12 | 14 | ChangeDetectionStrategy,
|
13 | 15 | Component,
|
14 | 16 | ElementRef,
|
| 17 | + ErrorHandler, |
| 18 | + inject, |
| 19 | + Inject, |
| 20 | + InjectionToken, |
15 | 21 | Input,
|
16 | 22 | OnChanges,
|
| 23 | + OnDestroy, |
17 | 24 | OnInit,
|
| 25 | + Optional, |
18 | 26 | SimpleChanges,
|
19 | 27 | ViewEncapsulation,
|
20 |
| - Optional, |
21 |
| - InjectionToken, |
22 |
| - inject, |
23 |
| - Inject, |
24 |
| - OnDestroy, |
25 |
| - AfterViewChecked, |
26 | 28 | } from '@angular/core';
|
27 |
| -import {DOCUMENT} from '@angular/common'; |
28 | 29 | import {CanColor, CanColorCtor, mixinColor} from '@angular/material/core';
|
29 |
| -import {coerceBooleanProperty} from '@angular/cdk/coercion'; |
| 30 | +import {take} from 'rxjs/operators'; |
| 31 | + |
30 | 32 | import {MatIconRegistry} from './icon-registry';
|
31 | 33 |
|
32 | 34 |
|
@@ -178,14 +180,15 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
|
178 | 180 | private _elementsWithExternalReferences?: Map<Element, {name: string, value: string}[]>;
|
179 | 181 |
|
180 | 182 | constructor(
|
181 |
| - elementRef: ElementRef<HTMLElement>, |
182 |
| - private _iconRegistry: MatIconRegistry, |
| 183 | + elementRef: ElementRef<HTMLElement>, private _iconRegistry: MatIconRegistry, |
183 | 184 | @Attribute('aria-hidden') ariaHidden: string,
|
184 | 185 | /**
|
185 | 186 | * @deprecated `location` parameter to be made required.
|
186 | 187 | * @breaking-change 8.0.0
|
187 | 188 | */
|
188 |
| - @Optional() @Inject(MAT_ICON_LOCATION) private _location?: MatIconLocation) { |
| 189 | + @Optional() @Inject(MAT_ICON_LOCATION) private _location?: MatIconLocation, |
| 190 | + // @breaking-change 9.0.0 _errorHandler parameter to be made required |
| 191 | + @Optional() private readonly _errorHandler?: ErrorHandler) { |
189 | 192 | super(elementRef);
|
190 | 193 |
|
191 | 194 | // If the user has not explicitly set aria-hidden, mark the icon as hidden, as this is
|
@@ -228,10 +231,17 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
|
228 | 231 | if (this.svgIcon) {
|
229 | 232 | const [namespace, iconName] = this._splitIconName(this.svgIcon);
|
230 | 233 |
|
231 |
| - this._iconRegistry.getNamedSvgIcon(iconName, namespace).pipe(take(1)).subscribe( |
232 |
| - svg => this._setSvgElement(svg), |
233 |
| - (err: Error) => console.log(`Error retrieving icon: ${err.message}`) |
234 |
| - ); |
| 234 | + this._iconRegistry.getNamedSvgIcon(iconName, namespace) |
| 235 | + .pipe(take(1)) |
| 236 | + .subscribe(svg => this._setSvgElement(svg), (err: Error) => { |
| 237 | + const errorMessage = `Error retrieving icon ${namespace}:${iconName}! ${err.message}`; |
| 238 | + // @breaking-change 9.0.0 _errorHandler parameter to be made required. |
| 239 | + if (this._errorHandler) { |
| 240 | + this._errorHandler.handleError(new Error(errorMessage)); |
| 241 | + } else { |
| 242 | + console.error(errorMessage); |
| 243 | + } |
| 244 | + }); |
235 | 245 | } else if (svgIconChanges.previousValue) {
|
236 | 246 | this._clearSvgElement();
|
237 | 247 | }
|
|
0 commit comments