Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resizable-directive): browser check for angular universal #83

Merged
merged 4 commits into from
Feb 28, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/resizable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import {
OnDestroy,
NgZone,
OnChanges,
SimpleChanges
SimpleChanges,
Inject,
PLATFORM_ID
} from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { Subject, Observable, Observer, merge, EMPTY } from 'rxjs';
import {
map,
Expand Down Expand Up @@ -374,6 +377,7 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy {
* @hidden
*/
constructor(
@Inject(PLATFORM_ID) private platformId: object,
private renderer: Renderer2,
public elm: ElementRef,
private zone: NgZone
Expand Down Expand Up @@ -688,7 +692,10 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy {
};
const resizeCursors = getResizeCursors();
const cursor = getResizeCursor(currentResize.edges, resizeCursors);
this.renderer.setStyle(document.body, 'cursor', cursor);
// browser check for angular universal, because it doesn't know what document is
if (isPlatformBrowser(this.platformId)) {
this.renderer.setStyle(document.body, 'cursor', cursor);
}
this.setElementClass(this.elm, RESIZE_ACTIVE_CLASS, true);
if (this.enableGhostResize) {
currentResize.clonedNode = this.elm.nativeElement.cloneNode(true);
Expand Down Expand Up @@ -754,7 +761,10 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy {
this.mouseup.subscribe(() => {
if (currentResize) {
this.renderer.removeClass(this.elm.nativeElement, RESIZE_ACTIVE_CLASS);
this.renderer.setStyle(document.body, 'cursor', '');
// browser check for angular universal, because it doesn't know what document is
if (isPlatformBrowser(this.platformId)) {
this.renderer.setStyle(document.body, 'cursor', '');
}
this.renderer.setStyle(this.elm.nativeElement, 'cursor', '');
this.zone.run(() => {
this.resizeEnd.emit({
Expand Down Expand Up @@ -785,7 +795,10 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy {
* @hidden
*/
ngOnDestroy(): void {
this.renderer.setStyle(document.body, 'cursor', '');
// browser check for angular universal, because it doesn't know what document is
if (isPlatformBrowser(this.platformId)) {
this.renderer.setStyle(document.body, 'cursor', '');
}
this.mousedown.complete();
this.mouseup.complete();
this.mousemove.complete();
Expand Down