Disable Cut, Copy and Paste function for textbox using AngularJs

后端 未结 4 641
天涯浪人
天涯浪人 2020-12-08 23:00

I want to disable copy paste in a textarea using angularJs. I tried to do so with ng-paste, like so:

Controller:

  angular.module(\'inputExample\', [         


        
相关标签:
4条回答
  • 2020-12-08 23:20

    The simplest way:

    <input ng-paste="$event.preventDefault();" placeholder='You cannot past here'>
    

    Working here

    0 讨论(0)
  • 2020-12-08 23:21

    you can do like this

    app.controller('MainCtrl', function($scope, $timeout) {....
    .......
    $scope.past = function() {
       $timeout(function() {
          $scope.val = " ";
       }, 0);
    }...
    

    here is the Demo Plunker

    0 讨论(0)
  • 2020-12-08 23:28

    Try making a directive that listens fot the cut, copy, and paste events and then prevent the default event action.

    app.directive('stopccp', function(){
        return {
            scope: {},
            link:function(scope,element){
                element.on('cut copy paste', function (event) {
                  event.preventDefault();
                });
            }
        };
    });
    

    Use by adding the attribute to the input box.

    <input stopccp ng-model="val" />
    

    Plunker

    You could also use the ng-copy, ng-cut and ng-paste directives and directly cancel the event.

    <input ng-cut="$event.preventDefault()" ng-copy="$event.preventDefault()" ng-paste="$event.preventDefault()" ng-model="val" />
    

    Plunker

    0 讨论(0)
  • 2020-12-08 23:43
    Try this;
    
     <input type="text" ng-paste="paste($event)" ng-model="name"/>
    

    In Controller

     app.controller('MainCtrl', function($scope) {
        $scope.name = 'World';
        $scope.paste = function(e){
           e.preventDefault();
           return false
        }
     });
    
    0 讨论(0)
提交回复
热议问题