【发布时间】:2018-01-22 10:25:51
【问题描述】:
当我需要在富文本中添加不可编辑的 html 时,我使用指令 textAngular 来格式化我的电子邮件通知文本并坚持执行任务。我在 textAngular 指令上添加了我的自定义指令。在我的自定义指令的帮助下,我将字符串中的特殊字符替换为带有参数contenteditable='false' 的 html span 标签,但是这个参数不起作用并且内容仍然可以编辑。
在这种情况下,我有两个问题:
- 如何在内容 textAngular 指令中设置不可编辑的 html?
- 如何将我的变量连接到想要放置的字符串(目前它总是连接到字符串的末尾)
感谢您的帮助。
Plunker我的问题
我的自定义指令:
app.directive('removeMarkers', function () {
return {
require: "ngModel",
link: function (scope, element, attrs, ngModel) {
element.bind('click', function (e) {
var target = e.target;
var parent = target.parentElement;
if (parent.classList.contains('label-danger')){
parent.remove()
}
});
function changeView(modelValue){
modelValue= modelValue
.replace(/\{{/g, "<span class='label label-danger' contenteditable='false' style='padding: 6px; color: #FFFFFF; font-size: 14px;'>")
.replace(/\}}/g, "<span contenteditable='false' class='remove-tag fa fa-times'></span></span> ");
ngModel.$modelValue= modelValue;
console.log(ngModel)
return modelValue;
}
ngModel.$formatters.push(changeView);
}
}
});
HTML
<select class="form-control pull-right"
style="max-width: 250px"
ng-options="label.name as label.label for label in variables"
ng-change="selectedEmailVariables(variable)"
ng-model="variable">
<option value="">template variables</option>
</select>
<div text-angular remove-markers name="email" ng-model="data.notifiation"></div>
【问题讨论】:
-
开发者似乎很不情愿添加这个功能。显然,ckeditor 是一个不错的选择。
标签: javascript html angularjs textangular