Skip to content

Commit dd73e36

Browse files
authored
refactor(icon): change deprecated APIs for version 10 (#19323)
Changes the APIs that were marked as deprecated for v10. BREAKING CHANGES: * The `_location` and `_errorHandler` parameters in the `MatIcon` constructor are now required. * The `_errorHandler` parameter in the `MatIconRegistry` constructor is now required.
1 parent e6e6d6f commit dd73e36

File tree

4 files changed

+23
-40
lines changed

4 files changed

+23
-40
lines changed

src/material/icon/icon-registry.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ export class MatIconRegistry implements OnDestroy {
137137
@Optional() private _httpClient: HttpClient,
138138
private _sanitizer: DomSanitizer,
139139
@Optional() @Inject(DOCUMENT) document: any,
140-
// @breaking-change 9.0.0 _errorHandler parameter to be made required
141-
@Optional() private readonly _errorHandler?: ErrorHandler) {
140+
private readonly _errorHandler: ErrorHandler) {
142141
this._document = document;
143142
}
144143

@@ -380,12 +379,7 @@ export class MatIconRegistry implements OnDestroy {
380379
// Swallow errors fetching individual URLs so the
381380
// combined Observable won't necessarily fail.
382381
const errorMessage = `Loading icon set URL: ${url} failed: ${err.message}`;
383-
// @breaking-change 9.0.0 _errorHandler parameter to be made required
384-
if (this._errorHandler) {
385-
this._errorHandler.handleError(new Error(errorMessage));
386-
} else {
387-
console.error(errorMessage);
388-
}
382+
this._errorHandler.handleError(new Error(errorMessage));
389383
return observableOf(null);
390384
})
391385
);
@@ -641,8 +635,8 @@ export function ICON_REGISTRY_PROVIDER_FACTORY(
641635
parentRegistry: MatIconRegistry,
642636
httpClient: HttpClient,
643637
sanitizer: DomSanitizer,
644-
document?: any,
645-
errorHandler?: ErrorHandler) {
638+
errorHandler: ErrorHandler,
639+
document?: any) {
646640
return parentRegistry || new MatIconRegistry(httpClient, sanitizer, document, errorHandler);
647641
}
648642

@@ -654,7 +648,7 @@ export const ICON_REGISTRY_PROVIDER = {
654648
[new Optional(), new SkipSelf(), MatIconRegistry],
655649
[new Optional(), HttpClient],
656650
DomSanitizer,
657-
[new Optional(), ErrorHandler],
651+
ErrorHandler,
658652
[new Optional(), DOCUMENT as InjectionToken<any>],
659653
],
660654
useFactory: ICON_REGISTRY_PROVIDER_FACTORY,

src/material/icon/icon.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
OnChanges,
2323
OnDestroy,
2424
OnInit,
25-
Optional,
2625
SimpleChanges,
2726
ViewEncapsulation,
2827
} from '@angular/core';
@@ -185,13 +184,8 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
185184
constructor(
186185
elementRef: ElementRef<HTMLElement>, private _iconRegistry: MatIconRegistry,
187186
@Attribute('aria-hidden') ariaHidden: string,
188-
/**
189-
* @deprecated `location` parameter to be made required.
190-
* @breaking-change 8.0.0
191-
*/
192-
@Optional() @Inject(MAT_ICON_LOCATION) private _location?: MatIconLocation,
193-
// @breaking-change 9.0.0 _errorHandler parameter to be made required
194-
@Optional() private readonly _errorHandler?: ErrorHandler) {
187+
@Inject(MAT_ICON_LOCATION) private _location: MatIconLocation,
188+
private readonly _errorHandler: ErrorHandler) {
195189
super(elementRef);
196190

197191
// If the user has not explicitly set aria-hidden, mark the icon as hidden, as this is
@@ -240,12 +234,7 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
240234
.pipe(take(1))
241235
.subscribe(svg => this._setSvgElement(svg), (err: Error) => {
242236
const errorMessage = `Error retrieving icon ${namespace}:${iconName}! ${err.message}`;
243-
// @breaking-change 9.0.0 _errorHandler parameter to be made required.
244-
if (this._errorHandler) {
245-
this._errorHandler.handleError(new Error(errorMessage));
246-
} else {
247-
console.error(errorMessage);
248-
}
237+
this._errorHandler.handleError(new Error(errorMessage));
249238
});
250239
} else if (svgIconChanges.previousValue) {
251240
this._clearSvgElement();
@@ -268,7 +257,7 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
268257
ngAfterViewChecked() {
269258
const cachedElements = this._elementsWithExternalReferences;
270259

271-
if (cachedElements && this._location && cachedElements.size) {
260+
if (cachedElements && cachedElements.size) {
272261
const newPath = this._location.getPathname();
273262

274263
// We need to check whether the URL has changed on each change detection since
@@ -310,13 +299,10 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
310299

311300
// Note: we do this fix here, rather than the icon registry, because the
312301
// references have to point to the URL at the time that the icon was created.
313-
if (this._location) {
314-
const path = this._location.getPathname();
315-
this._previousPath = path;
316-
this._cacheChildrenWithExternalReferences(svg);
317-
this._prependPathToReferences(path);
318-
}
319-
302+
const path = this._location.getPathname();
303+
this._previousPath = path;
304+
this._cacheChildrenWithExternalReferences(svg);
305+
this._prependPathToReferences(path);
320306
this._elementRef.nativeElement.appendChild(svg);
321307
}
322308

src/material/schematics/ng-update/data/constructor-checks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
3434
{
3535
pr: 'https://github.com/angular/components/pull/19363',
3636
changes: ['MatTooltip']
37+
},
38+
{
39+
pr: 'https://github.com/angular/components/pull/19323',
40+
changes: ['MatIcon', 'MatIconRegistry']
3741
}
3842
],
3943
[TargetVersion.V9]: [

tools/public_api_guard/material/icon.d.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export declare function getMatIconNoHttpProviderError(): Error;
88

99
export declare const ICON_REGISTRY_PROVIDER: {
1010
provide: typeof MatIconRegistry;
11-
deps: (Optional[] | typeof DomSanitizer)[];
11+
deps: (Optional[] | typeof DomSanitizer | typeof ErrorHandler)[];
1212
useFactory: typeof ICON_REGISTRY_PROVIDER_FACTORY;
1313
};
1414

15-
export declare function ICON_REGISTRY_PROVIDER_FACTORY(parentRegistry: MatIconRegistry, httpClient: HttpClient, sanitizer: DomSanitizer, document?: any, errorHandler?: ErrorHandler): MatIconRegistry;
15+
export declare function ICON_REGISTRY_PROVIDER_FACTORY(parentRegistry: MatIconRegistry, httpClient: HttpClient, sanitizer: DomSanitizer, errorHandler: ErrorHandler, document?: any): MatIconRegistry;
1616

1717
export interface IconOptions {
1818
viewBox?: string;
@@ -31,15 +31,14 @@ export declare class MatIcon extends _MatIconMixinBase implements OnChanges, OnI
3131
get inline(): boolean;
3232
set inline(inline: boolean);
3333
svgIcon: string;
34-
constructor(elementRef: ElementRef<HTMLElement>, _iconRegistry: MatIconRegistry, ariaHidden: string,
35-
_location?: MatIconLocation | undefined, _errorHandler?: ErrorHandler | undefined);
34+
constructor(elementRef: ElementRef<HTMLElement>, _iconRegistry: MatIconRegistry, ariaHidden: string, _location: MatIconLocation, _errorHandler: ErrorHandler);
3635
ngAfterViewChecked(): void;
3736
ngOnChanges(changes: SimpleChanges): void;
3837
ngOnDestroy(): void;
3938
ngOnInit(): void;
4039
static ngAcceptInputType_inline: BooleanInput;
4140
static ɵcmp: i0.ɵɵComponentDefWithMeta<MatIcon, "mat-icon", ["matIcon"], { "color": "color"; "inline": "inline"; "svgIcon": "svgIcon"; "fontSet": "fontSet"; "fontIcon": "fontIcon"; }, {}, never, ["*"]>;
42-
static ɵfac: i0.ɵɵFactoryDef<MatIcon, [null, null, { attribute: "aria-hidden"; }, { optional: true; }, { optional: true; }]>;
41+
static ɵfac: i0.ɵɵFactoryDef<MatIcon, [null, null, { attribute: "aria-hidden"; }, null, null]>;
4342
}
4443

4544
export interface MatIconLocation {
@@ -52,7 +51,7 @@ export declare class MatIconModule {
5251
}
5352

5453
export declare class MatIconRegistry implements OnDestroy {
55-
constructor(_httpClient: HttpClient, _sanitizer: DomSanitizer, document: any, _errorHandler?: ErrorHandler | undefined);
54+
constructor(_httpClient: HttpClient, _sanitizer: DomSanitizer, document: any, _errorHandler: ErrorHandler);
5655
addSvgIcon(iconName: string, url: SafeResourceUrl, options?: IconOptions): this;
5756
addSvgIconInNamespace(namespace: string, iconName: string, url: SafeResourceUrl, options?: IconOptions): this;
5857
addSvgIconLiteral(iconName: string, literal: SafeHtml, options?: IconOptions): this;
@@ -68,6 +67,6 @@ export declare class MatIconRegistry implements OnDestroy {
6867
ngOnDestroy(): void;
6968
registerFontClassAlias(alias: string, className?: string): this;
7069
setDefaultFontSetClass(className: string): this;
71-
static ɵfac: i0.ɵɵFactoryDef<MatIconRegistry, [{ optional: true; }, null, { optional: true; }, { optional: true; }]>;
70+
static ɵfac: i0.ɵɵFactoryDef<MatIconRegistry, [{ optional: true; }, null, { optional: true; }, null]>;
7271
static ɵprov: i0.ɵɵInjectableDef<MatIconRegistry>;
7372
}

0 commit comments

Comments
 (0)