Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 + Using Document Inject for Angular SSR
  • Loading branch information
EnricoMessall committed Mar 10, 2023
1 parent d962143 commit 659ec0c
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 17 deletions.
23 changes: 20 additions & 3 deletions src/app/components/button/button.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import { CommonModule } from '@angular/common';
import { AfterContentInit, AfterViewInit, ChangeDetectionStrategy, Component, ContentChildren, Directive, ElementRef, EventEmitter, Input, NgModule, OnDestroy, Output, QueryList, TemplateRef, ViewEncapsulation } from '@angular/core';
import {CommonModule, DOCUMENT} from '@angular/common';
import {
AfterContentInit,
AfterViewInit,
ChangeDetectionStrategy,
Component,
ContentChildren,
Directive,
ElementRef,
EventEmitter,
Inject,
Input,
NgModule,
OnDestroy,
Output,
QueryList,
TemplateRef,
ViewEncapsulation
} from '@angular/core';
import { PrimeTemplate } from 'primeng/api';
import { DomHandler } from 'primeng/dom';
import { RippleModule } from 'primeng/ripple';
Expand Down Expand Up @@ -81,7 +98,7 @@ export class ButtonDirective implements AfterViewInit, OnDestroy {

private _internalClasses: string[] = Object.values(INTERNAL_BUTTON_CLASSES);

constructor(public el: ElementRef) {}
constructor(public el: ElementRef, @Inject(DOCUMENT) private document: Document) {}

ngAfterViewInit() {
DomHandler.addMultipleClasses(this.htmlElement, this.getStyleClass().join(' '));
Expand Down
12 changes: 9 additions & 3 deletions src/app/components/confirmdialog/confirmdialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
TemplateRef,
AfterContentInit,
Output,
OnInit
OnInit, Inject
} from '@angular/core';
import { trigger, style, transition, animate, AnimationEvent, useAnimation, animation } from '@angular/animations';
import { CommonModule } from '@angular/common';
import {CommonModule, DOCUMENT} from '@angular/common';
import { DomHandler } from 'primeng/dom';
import { Footer, SharedModule, PrimeTemplate, PrimeNGConfig, TranslationKeys, ConfirmEventType } from 'primeng/api';
import { ButtonModule } from 'primeng/button';
Expand Down Expand Up @@ -262,7 +262,13 @@ export class ConfirmDialog implements AfterContentInit, OnInit, OnDestroy {

translationSubscription: Subscription;

constructor(public el: ElementRef, public renderer: Renderer2, private confirmationService: ConfirmationService, public zone: NgZone, private cd: ChangeDetectorRef, public config: PrimeNGConfig) {
constructor(public el: ElementRef,
public renderer: Renderer2,
private confirmationService: ConfirmationService,
public zone: NgZone,
private cd: ChangeDetectorRef,
public config: PrimeNGConfig,
@Inject(DOCUMENT) private document: Document) {
this.subscription = this.confirmationService.requireConfirmation$.subscribe((confirmation) => {
if (!confirmation) {
this.hide();
Expand Down
24 changes: 21 additions & 3 deletions src/app/components/confirmpopup/confirmpopup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { NgModule, Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, ChangeDetectorRef, OnDestroy, Input, EventEmitter, Renderer2 } from '@angular/core';
import { CommonModule } from '@angular/common';
import {
NgModule,
Component,
ChangeDetectionStrategy,
ViewEncapsulation,
ElementRef,
ChangeDetectorRef,
OnDestroy,
Input,
EventEmitter,
Renderer2,
Inject
} from '@angular/core';
import {CommonModule, DOCUMENT} from '@angular/common';
import { Confirmation, ConfirmationService, OverlayService, PrimeNGConfig, TranslationKeys } from 'primeng/api';
import { Subscription } from 'rxjs';
import { ButtonModule } from 'primeng/button';
Expand Down Expand Up @@ -116,7 +128,13 @@ export class ConfirmPopup implements OnDestroy {
this.cd.markForCheck();
}

constructor(public el: ElementRef, private confirmationService: ConfirmationService, public renderer: Renderer2, private cd: ChangeDetectorRef, public config: PrimeNGConfig, public overlayService: OverlayService) {
constructor(public el: ElementRef,
private confirmationService: ConfirmationService,
public renderer: Renderer2,
private cd: ChangeDetectorRef,
public config: PrimeNGConfig,
public overlayService: OverlayService,
@Inject(DOCUMENT) private document: Document) {
this.subscription = this.confirmationService.requireConfirmation$.subscribe((confirmation) => {
if (!confirmation) {
this.hide();
Expand Down
15 changes: 13 additions & 2 deletions src/app/components/dynamicdialog/dialogservice.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { Injectable, ComponentFactoryResolver, ApplicationRef, Injector, Type, EmbeddedViewRef, ComponentRef } from '@angular/core';
import {
Injectable,
ComponentFactoryResolver,
ApplicationRef,
Injector,
Type,
EmbeddedViewRef,
ComponentRef,
Inject
} from '@angular/core';
import { DynamicDialogComponent } from './dynamicdialog';
import { DynamicDialogInjector } from './dynamicdialog-injector';
import { DynamicDialogConfig } from './dynamicdialog-config';
import { DynamicDialogRef } from './dynamicdialog-ref';
import {DOCUMENT} from "@angular/common";

@Injectable()
export class DialogService {
dialogComponentRefMap: Map<DynamicDialogRef, ComponentRef<DynamicDialogComponent>> = new Map();

constructor(private componentFactoryResolver: ComponentFactoryResolver, private appRef: ApplicationRef, private injector: Injector) {}
constructor(private componentFactoryResolver: ComponentFactoryResolver, private appRef: ApplicationRef,
private injector: Injector, @Inject(DOCUMENT) private document: Document) {}

public open(componentType: Type<any>, config: DynamicDialogConfig) {
const dialogRef = this.appendDialogComponentToBody(config);
Expand Down
24 changes: 21 additions & 3 deletions src/app/components/scrollpanel/scrollpanel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import { NgModule, Component, Input, AfterViewInit, OnDestroy, ElementRef, NgZone, ViewChild, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, AfterContentInit, ContentChildren, QueryList, TemplateRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import {
NgModule,
Component,
Input,
AfterViewInit,
OnDestroy,
ElementRef,
NgZone,
ViewChild,
ChangeDetectionStrategy,
ViewEncapsulation,
ChangeDetectorRef,
AfterContentInit,
ContentChildren,
QueryList,
TemplateRef,
Inject
} from '@angular/core';
import {CommonModule, DOCUMENT} from '@angular/common';
import { DomHandler } from 'primeng/dom';
import { PrimeTemplate } from 'primeng/api';

Expand Down Expand Up @@ -29,7 +46,8 @@ export class ScrollPanel implements AfterViewInit, AfterContentInit, OnDestroy {

@Input() styleClass: string;

constructor(public el: ElementRef, public zone: NgZone, public cd: ChangeDetectorRef) {}
constructor(public el: ElementRef, public zone: NgZone, public cd: ChangeDetectorRef,
@Inject(DOCUMENT) private document: Document) {}

@ViewChild('container') containerViewChild: ElementRef;

Expand Down
6 changes: 3 additions & 3 deletions src/app/components/speeddial/speeddial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
ViewChild,
OnDestroy,
OnInit,
AfterViewInit
AfterViewInit, Inject
} from '@angular/core';
import { CommonModule } from '@angular/common';
import {CommonModule, DOCUMENT} from '@angular/common';
import { SharedModule, PrimeTemplate, MenuItem } from 'primeng/api';
import { ButtonModule } from 'primeng/button';
import { RippleModule } from 'primeng/ripple';
Expand Down Expand Up @@ -161,7 +161,7 @@ export class SpeedDial implements AfterViewInit, AfterContentInit, OnDestroy {

documentClickListener: any;

constructor(private el: ElementRef, public cd: ChangeDetectorRef) {}
constructor(private el: ElementRef, public cd: ChangeDetectorRef, @Inject(DOCUMENT) private document: Document) {}

ngAfterViewInit() {
if (this.type !== 'linear') {
Expand Down

0 comments on commit 659ec0c

Please sign in to comment.