Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
fix(ssr): fixed ServerRendering error
Browse files Browse the repository at this point in the history
  • Loading branch information
TINANT Hervé committed Jul 10, 2017
1 parent c86ac75 commit 2224478
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/lib/src/directive/off-click.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Directive, HostListener, Input, OnInit, OnDestroy } from '@angular/core';
import { Directive, HostListener, Input, OnInit, OnDestroy, PLATFORM_ID, Inject } from '@angular/core';
import {isPlatformBrowser} from '@angular/common';

@Directive({
selector: '[cra-off-click]'
Expand All @@ -8,16 +9,18 @@ export class OffClickDirective implements OnInit, OnDestroy {
@Input('cra-off-click')
public offClickHandler: any;
/* tslint:enable */
// @HostListener('click', ['$event'])
// public onClick($event: MouseEvent): void {
// $event.stopPropagation();
// }

constructor(@Inject(PLATFORM_ID) private platformId: string) {}

public ngOnInit(): any {
setTimeout(() => { document.addEventListener('click', this.offClickHandler); }, 0);
if (isPlatformBrowser(this.platformId)) {
setTimeout(() => { document.addEventListener('click', this.offClickHandler); }, 0);
}
}

public ngOnDestroy(): any {
document.removeEventListener('click', this.offClickHandler);
if (isPlatformBrowser(this.platformId)) {
document.removeEventListener('click', this.offClickHandler);
}
}
}

0 comments on commit 2224478

Please sign in to comment.