Last active
July 28, 2018 18:56
-
-
Save iSanjayAchar/6bc484c8454bb61393b3135f4292673b to your computer and use it in GitHub Desktop.
Disabled Clipboard Actions: Angular 2+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div appDisableClipboard> | |
<!-- | |
Your HTML Content here | |
--> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this Angular 2+ Directive to disable Clipboard actions like Copy, Cut & Paste.