Skip to content

Instantly share code, notes, and snippets.

@Muzammil-Bilwani
Created July 8, 2019 13:14
Show Gist options
  • Save Muzammil-Bilwani/270bbc8768b8f5f4ad68ac9009f33a76 to your computer and use it in GitHub Desktop.
Save Muzammil-Bilwani/270bbc8768b8f5f4ad68ac9009f33a76 to your computer and use it in GitHub Desktop.
Block Copy Paste in Angular for Input fields
import { Directive, HostListener } from '@angular/core';
@Directive({
selector: '[CopyPasteBlock]'
})
export class CopyPasteBlockDirective {
constructor() { }
@HostListener('paste', ['$event']) blockPaste(e: KeyboardEvent) {
e.preventDefault();
}
@HostListener('copy', ['$event']) blockCopy(e: KeyboardEvent) {
e.preventDefault();
}
@HostListener('cut', ['$event']) blockCut(e: KeyboardEvent) {
e.preventDefault();
}
}
@Zoulfa-jn
Copy link

hello ,
i want to disabled copy paste for a field not at all my field how kan i specify that

@Hellonate88
Copy link

Hi, I want to know any chance to disable cut copy paste menu. not only the function for cut copy and paste. Thanks

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