Gets the name of the icon.
()
| 39 | |
| 40 | /** Gets the name of the icon. */ |
| 41 | async getName(): Promise<string | null> { |
| 42 | const host = await this.host(); |
| 43 | const nameFromDom = await host.getAttribute('data-mat-icon-name'); |
| 44 | |
| 45 | // If we managed to figure out the name from the attribute, use it. |
| 46 | if (nameFromDom) { |
| 47 | return nameFromDom; |
| 48 | } |
| 49 | |
| 50 | // Some icons support defining the icon as a ligature. |
| 51 | // As a fallback, try to extract it from the DOM text. |
| 52 | if ((await this.getType()) === IconType.FONT) { |
| 53 | // Other directives may add content to the icon (e.g. `MatBadge`), however only the direct |
| 54 | // text nodes affect the name of the icon. Exclude all element descendants from the result. |
| 55 | const text = await host.text({exclude: '*'}); |
| 56 | |
| 57 | // There are some internal cases where the icon name is wrapped in another node. |
| 58 | // Fall back to extracting the entire text if we ended up excluding everything above. |
| 59 | return text.length > 0 ? text : host.text(); |
| 60 | } |
| 61 | |
| 62 | return null; |
| 63 | } |
| 64 | |
| 65 | /** Gets the namespace of the icon. */ |
| 66 | async getNamespace(): Promise<string | null> { |
no test coverage detected