MCPcopy Create free account
hub / github.com/angular/components / setAppearance

Method setAppearance

src/material/button/button.ts:69–88  ·  view source on GitHub ↗

Programmatically sets the appearance of the button.

(appearance: MatButtonAppearance)

Source from the content-addressed store, hash-verified

67
68 /** Programmatically sets the appearance of the button. */
69 setAppearance(appearance: MatButtonAppearance): void {
70 if (appearance === this._appearance) {
71 return;
72 }
73
74 const classList = this._elementRef.nativeElement.classList;
75 const previousClasses = this._appearance ? APPEARANCE_CLASSES.get(this._appearance) : null;
76 const newClasses = APPEARANCE_CLASSES.get(appearance)!;
77
78 if ((typeof ngDevMode === 'undefined' || ngDevMode) && !newClasses) {
79 throw new Error(`Unsupported MatButton appearance "${appearance}"`);
80 }
81
82 if (previousClasses) {
83 classList.remove(...previousClasses);
84 }
85
86 classList.add(...newClasses);
87 this._appearance = appearance;
88 }
89}
90
91/** Infers the button's appearance from its static attributes. */

Callers 2

appearanceMethod · 0.95
constructorMethod · 0.95

Calls 3

getMethod · 0.65
removeMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected