Skip to content

Instantly share code, notes, and snippets.

@pawiromitchel
Created August 31, 2021 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawiromitchel/c117f495f0c23b20c538abf015448aa9 to your computer and use it in GitHub Desktop.
Save pawiromitchel/c117f495f0c23b20c538abf015448aa9 to your computer and use it in GitHub Desktop.
Create a custom BlockUI component and reuse it

Create a custom component in your project
Source from: https://stackoverflow.com/questions/52174754/having-a-primeng-blockableui-interfaced-component-with-minimal-style

import { Component, ElementRef, Input } from '@angular/core';
import { BlockableUI } from 'primeng/primeng';

@Component({
  selector: 'app-blockable-div',
  template: `<div [ngStyle]="style" [ngClass]="class" ><ng-content></ng-content></div>`
})
export class BlockableDivComponent implements BlockableUI {

  @Input() style: any;
  @Input() class: any;

  constructor(private el: ElementRef) {
  }

  getBlockableElement(): HTMLElement { 
      return this.el.nativeElement.children[0];
  }
}

Import it in the declarations in the @NgModule you want to use

Use it

<p-blockUI [blocked]="blockUI" [target]="pnl"></p-blockUI>

<app-blockable-div #pnl>
  ...
</app-blockable-div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment