我使用指令textAngular來格式化我的電子郵件通知文本,並在需要添加不可編輯的html內部文本時停留在任務中。我通過textAngular指令添加了自定義指令。藉助我的自定義指令,我將字符串中的特殊字符替換爲參數contenteditable='false'
的html span標籤,但是此參數不起作用,並且內容仍然可編輯。帶有非可編輯內容的豐富文本,angularjs
在這種情況下,我有兩個問題:
- 如何內容textAngular指令裏面我設置不可編輯HTML?
- 我如何Concat的我的變量字符串到希望的地方(目前它總是concats到字符串的結尾)
我感謝所有幫助。
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。 – Deckerz