Skip to content

Commit e9a9472

Browse files
committed
Better Angular Universal support.
1 parent 0d24711 commit e9a9472

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-svg-round-progressbar",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Angular module that uses SVG to create a circular progressbar",
55
"scripts": {},
66
"repository": {

src/round-progress.component.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import {
44
Output,
55
OnChanges,
66
NgZone,
7-
ElementRef,
87
EventEmitter,
8+
ViewChild,
9+
Renderer,
910
} from '@angular/core';
1011

1112
import { RoundProgressService } from './round-progress.service';
@@ -25,6 +26,7 @@ import { RoundProgressEase } from './round-progress.ease';
2526
[style.stroke-width]="stroke"/>
2627
2728
<path
29+
#path
2830
fill="none"
2931
[style.stroke-width]="stroke"
3032
[style.stroke]="_service.resolveColor(color)"
@@ -33,7 +35,7 @@ import { RoundProgressEase } from './round-progress.ease';
3335
</svg>
3436
`,
3537
host: {
36-
role: 'progressbar',
38+
'role': 'progressbar',
3739
'[attr.aria-valuemin]': 'current',
3840
'[attr.aria-valuemax]': 'max',
3941
'[style.width]': "responsive ? '' : _diameter + 'px'",
@@ -61,15 +63,15 @@ import { RoundProgressEase } from './round-progress.ease';
6163
]
6264
})
6365
export class RoundProgressComponent implements OnChanges {
64-
private _path: SVGPathElement;
66+
@ViewChild('path') private _path;
6567
private _lastAnimationId: number = 0;
6668

6769
constructor(
6870
private _service: RoundProgressService,
6971
private _easingFunctions: RoundProgressEase,
7072
private _defaults: RoundProgressConfig,
7173
private _ngZone: NgZone,
72-
private _element: ElementRef
74+
private _renderer: Renderer
7375
) {}
7476

7577
/** Animates a change in the current value. */
@@ -115,12 +117,10 @@ export class RoundProgressComponent implements OnChanges {
115117

116118
/** Sets the path dimensions. */
117119
private _setPath(value: number): void {
118-
if (!this._path) {
119-
this._path = this._element.nativeElement.querySelector('path');
120+
if (this._path) {
121+
this._renderer.setElementAttribute(this._path.nativeElement, 'd', this._service.getArc(value,
122+
this.max, this.radius - this.stroke / 2, this.radius, this.semicircle));
120123
}
121-
122-
this._path.setAttribute('d', this._service.getArc(value, this.max,
123-
this.radius - this.stroke / 2, this.radius, this.semicircle));
124124
}
125125

126126
/** Clamps a value between the maximum and 0. */

src/round-progress.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Injectable } from '@angular/core';
22

33
const DEGREE_IN_RADIANS: number = Math.PI / 180;
4-
const BASE: HTMLBaseElement = document.head.querySelector('base');
4+
const HAS_DOCUMENT = typeof document !== 'undefined';
5+
const BASE: HTMLBaseElement = HAS_DOCUMENT && document.head.querySelector('base');
56
const HAS_PERF =
7+
typeof window !== 'undefined' &&
68
window.performance &&
79
window.performance.now &&
810
typeof window.performance.now() === 'number';
@@ -13,6 +15,7 @@ export class RoundProgressService {
1315

1416
constructor() {
1517
this.supportsSvg = !!(
18+
HAS_DOCUMENT &&
1619
document.createElementNS &&
1720
document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect
1821
);

0 commit comments

Comments
 (0)