Programmatically sets the appearance of the button.
(appearance: MatButtonAppearance)
| 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. */ |
no test coverage detected