Angular之编辑器插件

匿名 (未验证) 提交于 2019-12-03 00:36:02

第一步,导入:

<script src="ngUeditor.js"></script>

第二步,引入Js文件

app.directive('ngUeditor', function () {     return {         restrict: 'AE',         transclude: true,         replace: true,         template: '<script name="content" type="text/plain" ng-transclude @style></script>',         require: '?ngModel',         scope: {             config: '=',             style:'@'         },         link: function (scope, element, attrs, ngModel) {             var editor = new UE.ui.Editor(scope.config || {});             var _editorId = attrs.id ? attrs.id : "_editor" + (Date.now());             element[0].id = _editorId;             editor.render(element[0]);              editor.ready(function()             {                 //图片上传回调                 editor.addListener('beforeInsertImage', function (t, arg) {                     if(scope.config.imageUploadCallback){                         scope.config.imageUploadCallback(arg);                     }                 });                 //侦听文件上传,取上传文件列表中第一个上传的文件的路径                 editor.addListener('afterUpfile', function (t, arg) {                     if(scope.config.fileUploadCallback){                         scope.config.fileUploadCallback(arg);                     }                 });                  if(scope.config.getEditor){                     scope.config.getEditor(editor);                 }                  if (ngModel) {                     //Model数据更新时,更新百度UEditor                     ngModel.$render = function () {                         try {                             editor.setContent(ngModel.$viewValue);                         } catch (e) {                          }                     };                     ngModel.$render(); //一开始加载渲染数据                     //百度UEditor数据更新时,更新Model                     editor.addListener('contentChange', function () {                         setTimeout(function () {                             scope.$apply(function () {                                 ngModel.$setViewValue(editor.getContent());                             })                         }, 0);                     })                 }              });         }     } });

第三步,调用ngUeditor

var 模块名 = angular.module('模块名',['ngUeditor',……]

第四步,使用<ng-ueditor>

<ng-ueditor id="descriptionContainer" class="ueditContainer"                                     config="editorConfig" ng-model="notify.notification"                                     style="width:800px;height:400px"> </ng-ueditor>


效果如下:

欢迎各位大佬留言~

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!