0

I am using ngPaste on a contentEditable div instead of input type text. However, I am unable to fetch the pasted content in the way mention in this link. I am always getting undefined in my handler for ngPaste. Here's the code:

HTML:

<div contentEditable="true" ng-paste="stripHtml($event.clipboardData.getData('text/plain'))">
</div

>

JS:

scope.stripHtml = function(content) {
    console.log(content); //this is always undefined
}

What am I doing wrong? How can I fetch the pasted content?

Community
  • 1
  • 1
Tarun Dugar
  • 8,451
  • 6
  • 38
  • 68

1 Answers1

0

The Below Code (Modified from Sergey's) Worked in Windows platform, Firefox 43.0.4, Chrome 47.0.2526.111 m but NOT in IE 11.0.9.

<!DOCTYPE html>
<html>
<head>

<style>

.editable {
  background: white;
  height: 55px;
  border: 2px solid blue;
  width: 55%;
}

</style>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script>

<script>

var myApp = angular.module('myApp', []);
myApp.controller('sampleController', function($scope) {

    $scope.stripHtml = function(content) {
       alert(content);
       console.log(content); 
    };

});

</script>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>AngularJS ng-paste within ContentEditable Div</title>
</head>
<body ng-app="myApp">
  <div ng-controller="sampleController">

    <div class="editable" contentEditable="true" ng-paste="stripHtml($event.clipboardData.getData('text/plain'))"></div>

  </div>
</body>
</html>
Jenson M John
  • 4,972
  • 4
  • 25
  • 45
  • But the function is getting called. If content editable didn't support ngPaste, the function handler for ngPaste shouldn't even have been called. – Tarun Dugar Jan 18 '16 at 11:24