Skip to content

Instantly share code, notes, and snippets.

@iSanjayAchar
Last active July 28, 2018 18:56
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 iSanjayAchar/6bc484c8454bb61393b3135f4292673b to your computer and use it in GitHub Desktop.
Save iSanjayAchar/6bc484c8454bb61393b3135f4292673b to your computer and use it in GitHub Desktop.
Disabled Clipboard Actions: Angular 2+
<div appDisableClipboard>
<!--
Your HTML Content here
-->
</div>
import { Directive, ElementRef, Renderer } from '@angular/core';
@Directive({
selector: '[appDisableClipboard]'
})
export class DisableClipboardDirective {
constructor(
el: ElementRef,
renderer: Renderer
) {
let events = 'cut copy paste';
events.split(' ').forEach(e =>
renderer.listen(el.nativeElement, e, (event) => {
event.preventDefault();
})
)
}
}
@iSanjayAchar
Copy link
Author

Use this Angular 2+ Directive to disable Clipboard actions like Copy, Cut & Paste.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment