angularjs 与 UEditor开发,添加directive,保证加载顺序正常

'use strict';
angular.module('app.core').directive('ueditor', [function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ctrl) { var _initContent = '';
var editor;
var editorReady = false; ctrl.$render = function () {
_initContent = ctrl.$isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue;
setContent(_initContent);
}; function init() {
editor = new UE.ui.Editor({
initialContent: scope.content,
wordCount: false, // 字数统计
elementPathEnabled: false, // 元素路径
autoFloatEnabled: false, // 工具栏浮动
autoHeightEnabled: false, // 自动长高
toolbars: [
[
'source', 'fontsize', '|',
'blockquote', 'horizontal', '|',
'removeformat', '|',
'bold', 'italic', 'underline', 'forecolor', 'backcolor', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify',
'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
'insertorderedlist', 'i
nsertunorderedlist', '|',
'link', 'unlink', '|',
'insertimage', 'music', 'insertvideo', 'template'
]
]
});
editor.render(element[0]);
editor.ready(function () {
editorReady = true;
setContent(_initContent);
editor.addListener('contentChange', function () {
if (!scope.$$phase) {
scope.$apply(function () {
ctrl.$setViewValue(editor.getContent());
});
}
});
});
}
function setContent(content) {
if (editor && editorReady) {
editor.setContent(content);
}
} init();
}
};
}]);

在html代码中引用文章来源地址https://www.yii666.com/article/756076.html网址:yii666.com

<div name="content" ueditor ng-model="content" ng-change="contentChanged()" ng-required="true"></div>

在controller中初始化及赋值文章地址https://www.yii666.com/article/756076.html网址:yii666.com<文章来源地址:https://www.yii666.com/article/756076.html

初始化 $scope.content="";
赋值:$scope.content="<b>abcdefg</b>"

版权声明:本文内容来源于网络,版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。文本页已经标记具体来源原文地址,请点击原文查看来源网址,站内文章以及资源内容站长不承诺其正确性,如侵犯了您的权益,请联系站长如有侵权请联系站长,将立刻删除

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信图片_20190322181744_03.jpg

微信扫一扫打赏

请作者喝杯咖啡吧~

支付宝扫一扫领取红包,优惠每天领

二维码1

zhifubaohongbao.png

二维码2

zhifubaohongbao2.png