我在contentEditable div而不是输入类型文本上使用ngPaste
。但是,我无法以link.中提到的方式获取粘贴的内容。我总是在ngPaste
的处理程序中未定义。这是代码:
HTML:
<div contentEditable="true" ng-paste="stripHtml($event.clipboardData.getData('text/plain'))">
</div
&GT;
JS:
scope.stripHtml = function(content) {
console.log(content); //this is always undefined
}
我做错了什么?如何获取粘贴的内容?
答案 0 :(得分:0)
以下代码(由Sergey&s。修改)在Windows平台,Firefox 43.0.4,Chrome 47.0.2526.111 m中工作,但不在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>