|
9 | 9 | import {AriaDescriber} from '@angular/cdk/a11y';
|
10 | 10 | import {coerceBooleanProperty} from '@angular/cdk/coercion';
|
11 | 11 | import {DOCUMENT} from '@angular/common';
|
12 |
| -import {Directive, ElementRef, Inject, Input, NgZone, OnDestroy, Optional} from '@angular/core'; |
| 12 | +import { |
| 13 | + Directive, |
| 14 | + ElementRef, |
| 15 | + Inject, |
| 16 | + Input, |
| 17 | + NgZone, |
| 18 | + OnDestroy, |
| 19 | + Optional, |
| 20 | + Renderer2, |
| 21 | +} from '@angular/core'; |
13 | 22 | import {ThemePalette} from '@angular/material/core';
|
14 | 23 |
|
15 | 24 |
|
@@ -102,7 +111,9 @@ export class MatBadge implements OnDestroy {
|
102 | 111 | @Optional() @Inject(DOCUMENT) private _document: any,
|
103 | 112 | private _ngZone: NgZone,
|
104 | 113 | private _elementRef: ElementRef<HTMLElement>,
|
105 |
| - private _ariaDescriber: AriaDescriber) {} |
| 114 | + private _ariaDescriber: AriaDescriber, |
| 115 | + /** @breaking-change 8.0.0 Make _renderer a required param and remove _document. */ |
| 116 | + private _renderer?: Renderer2) {} |
106 | 117 |
|
107 | 118 | /** Whether the badge is above the host or not */
|
108 | 119 | isAbove(): boolean {
|
@@ -132,7 +143,9 @@ export class MatBadge implements OnDestroy {
|
132 | 143 |
|
133 | 144 | /** Creates the badge element */
|
134 | 145 | private _createBadgeElement(): HTMLElement {
|
135 |
| - const badgeElement = this._document.createElement('span'); |
| 146 | + // @breaking-change 8.0.0 Remove null check for _renderer |
| 147 | + const rootNode = this._renderer || this._document; |
| 148 | + const badgeElement = rootNode.createElement('span'); |
136 | 149 | const activeClass = 'mat-badge-active';
|
137 | 150 |
|
138 | 151 | badgeElement.setAttribute('id', `mat-badge-content-${this._id}`);
|
|
0 commit comments