angular ckeditor 编辑文字
2016-08-23 12:03
162 查看
先下载ckeditor
并且在index 中引用
<script src="lib/ckeditor/ckeditor.js"></script>
html 中代码:
<form action="">
<textarea ckeditor ng-model="dataAll122.Name" class="form-control" name="content"></textarea>
</form>
<button ng-click="clickAlert()">获得数据</button>
controller中代码:
$scope.dataAll122 = {
'Name': '',//
};
directive 中的代码
.directive('ckeditor', function() {
return {
require : '?ngModel',
link : function(scope, element, attrs, ngModel) {
var ckeditor = CKEDITOR.replace(element[0], {
});
if (!ngModel) {
return;
}
ckeditor.on('instanceReady', function() {
ckeditor.setData(ngModel.$viewValue);
});
ckeditor.on('pasteState', function() {
scope.$apply(function() {
ngModel.$setViewValue(ckeditor.getData());
});
});
ngModel.$render = function(value) {
ckeditor.setData(ngModel.$viewValue);
};
}
};
});
并且在index 中引用
<script src="lib/ckeditor/ckeditor.js"></script>
html 中代码:
<form action="">
<textarea ckeditor ng-model="dataAll122.Name" class="form-control" name="content"></textarea>
</form>
<button ng-click="clickAlert()">获得数据</button>
controller中代码:
$scope.dataAll122 = {
'Name': '',//
};
$scope.removeHTMLTag = function (str) { str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白 //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行 str=str.replace(/ /ig,'');//去掉 str=str.replace(/\s/g,''); //将空格去掉 return str; } //获取纯文本 $scope.clickAlert = function(){ console.log("-------"); console.log($scope.dataAll122.Name); $scope.xudesong = $scope.dataAll122.Name, $scope.xudesong= $scope.removeHTMLTag( $scope.dataAll122.Name); console.log( $scope.xudesong); }
directive 中的代码
.directive('ckeditor', function() {
return {
require : '?ngModel',
link : function(scope, element, attrs, ngModel) {
var ckeditor = CKEDITOR.replace(element[0], {
});
if (!ngModel) {
return;
}
ckeditor.on('instanceReady', function() {
ckeditor.setData(ngModel.$viewValue);
});
ckeditor.on('pasteState', function() {
scope.$apply(function() {
ngModel.$setViewValue(ckeditor.getData());
});
});
ngModel.$render = function(value) {
ckeditor.setData(ngModel.$viewValue);
};
}
};
});
相关文章推荐
- 基于angular上传图片并能对图片裁剪,放大缩小,压缩size及在图片上添加文字等编辑操作,并能手动限制上传图片数量
- ckeditor文字编辑和图片上传
- PDF编辑技巧4:删除水印、编辑图片和文字
- 在可编辑div中插入文字或图片的问题解决思路
- 文字编辑距离代码实现
- kindeditor-网页文字编辑
- Angular实现的敏感文字自动过滤与提示功能示例
- TX Text Control文字处理教程(6)通过代码编辑和格式化文本
- PDF文字怎样编辑 如何修改PDF文档
- 文本框文字居中编辑 显示
- CKeditor设置编辑区填充内容,并设置不可编辑
- angular 实现等待一段时间显示文字
- 出现C#编辑后,窗口中的txetBox中无法输入文字
- MFC中改变编辑框文字大小、颜色的方法
- 【转载】HTML之文字版面的编辑(三)
- 使用 CKEditor编辑插件
- 编辑文字,图片,网页
- 扫描件如何转可编辑Word?扫描件转文字技巧分享
- jQuery Form Plugin以ajax方式提交CKEditor编辑的内容丢失
- 双击实现文字编辑