zoomla
Version:
16年专业研发|中文alexa排名第一的CMS品牌-基于dotNET core、功能强大,集成站群、微信开发、小程序与ERP及OA办公系统,支持国际语言和多民族语言,世界五百强与大型门户专用高端网站内核CMS系统
35 lines (33 loc) • 1.3 kB
JavaScript
function InitAngularCMD() {
app.directive('contenteditable', function () {
return {
require: '?ngModel',
link: function (scope, element, attrs, ctrl) {
// Do nothing if this is not bound to a model
if (!ctrl) { }
// Checks for updates (input or pressing ENTER)
// view -> model
element.bind('input enterKey', function () {
var rerender = false;
var html = element.html();
if (attrs.noLineBreaks) {
//html = html.replace(/<div>/g, '').replace(/<br>/g, '').replace(/<\/div>/g, '');
rerender = true;
}
scope.$apply(function () {
ctrl.$setViewValue(html);
if (rerender) {
ctrl.$render();
}
});
});
// model -> view
ctrl.$render = function () {
element.html(ctrl.$viewValue);
};
// load init value from DOM
ctrl.$render();
}
};
});
}