admin管理员组文章数量:1026989
I use directive textAngular to format my email notification text and stuck for while with task when I need to add non editable html inside rich text. I added my custom directive over textAngular directive. With help my custom directive I replace special characters in the string to html span tags with param contenteditable='false'
, but this param doesn't work and content still editable.
In this case I have two questions:
- How can I setup non-editable html inside content textAngular directive?
- How can I concat my variable to the string to desire place (currently it always concats to the end of the string)
I appreciate any help.
Plunker with my problem
My custom directive:
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>
I use directive textAngular to format my email notification text and stuck for while with task when I need to add non editable html inside rich text. I added my custom directive over textAngular directive. With help my custom directive I replace special characters in the string to html span tags with param contenteditable='false'
, but this param doesn't work and content still editable.
In this case I have two questions:
- How can I setup non-editable html inside content textAngular directive?
- How can I concat my variable to the string to desire place (currently it always concats to the end of the string)
I appreciate any help.
Plunker with my problem
My custom directive:
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>
Share
Improve this question
edited Aug 14, 2017 at 17:38
antonyboom
asked Aug 14, 2017 at 14:33
antonyboomantonyboom
1,1812 gold badges17 silver badges47 bronze badges
1
- It seems the developers are very reluctant to add this feature. Apparently a good alternative is ckeditor. – Deckerz Commented Aug 16, 2017 at 15:10
1 Answer
Reset to default 12 +501) You can't simply use contenteditable='false'
attribute on your elements, since textAngular
strips it. To enable it in the past we had to download textAngular-sanitize.min.js
and edit the array of allowed attributes. This starts with J=f("abbr,align,
, you have to simply add contenteditable
to this ma separated list.
2) To insert the template to the cursor position you can use wrapSelection
method within editor scope, something like this could work:
$scope.selectedEmailVariables = function (item) {
if (item !== null) {
var editorScope = textAngularManager.retrieveEditor('editor1').scope;
editorScope.displayElements.text[0].focus();
editorScope.wrapSelection('insertHtml',
" <span class='label label-danger' contenteditable='false' style='color: #FFFFFF; font-size: 14px;'>" + item + "<span contenteditable='false' class='remove-tag fa fa-times'></span></span> ", true);
}
};
Here is a working plnkr.
P.S.: textAngular
seems to be a good editor, but it lacks some of the functionality and personally, I don't like its documentation. You have to gather a lot of info through the issues on the github. Right now switched to the other alternative editors, but possibly will get back to it in the future.
I use directive textAngular to format my email notification text and stuck for while with task when I need to add non editable html inside rich text. I added my custom directive over textAngular directive. With help my custom directive I replace special characters in the string to html span tags with param contenteditable='false'
, but this param doesn't work and content still editable.
In this case I have two questions:
- How can I setup non-editable html inside content textAngular directive?
- How can I concat my variable to the string to desire place (currently it always concats to the end of the string)
I appreciate any help.
Plunker with my problem
My custom directive:
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>
I use directive textAngular to format my email notification text and stuck for while with task when I need to add non editable html inside rich text. I added my custom directive over textAngular directive. With help my custom directive I replace special characters in the string to html span tags with param contenteditable='false'
, but this param doesn't work and content still editable.
In this case I have two questions:
- How can I setup non-editable html inside content textAngular directive?
- How can I concat my variable to the string to desire place (currently it always concats to the end of the string)
I appreciate any help.
Plunker with my problem
My custom directive:
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>
Share
Improve this question
edited Aug 14, 2017 at 17:38
antonyboom
asked Aug 14, 2017 at 14:33
antonyboomantonyboom
1,1812 gold badges17 silver badges47 bronze badges
1
- It seems the developers are very reluctant to add this feature. Apparently a good alternative is ckeditor. – Deckerz Commented Aug 16, 2017 at 15:10
1 Answer
Reset to default 12 +501) You can't simply use contenteditable='false'
attribute on your elements, since textAngular
strips it. To enable it in the past we had to download textAngular-sanitize.min.js
and edit the array of allowed attributes. This starts with J=f("abbr,align,
, you have to simply add contenteditable
to this ma separated list.
2) To insert the template to the cursor position you can use wrapSelection
method within editor scope, something like this could work:
$scope.selectedEmailVariables = function (item) {
if (item !== null) {
var editorScope = textAngularManager.retrieveEditor('editor1').scope;
editorScope.displayElements.text[0].focus();
editorScope.wrapSelection('insertHtml',
" <span class='label label-danger' contenteditable='false' style='color: #FFFFFF; font-size: 14px;'>" + item + "<span contenteditable='false' class='remove-tag fa fa-times'></span></span> ", true);
}
};
Here is a working plnkr.
P.S.: textAngular
seems to be a good editor, but it lacks some of the functionality and personally, I don't like its documentation. You have to gather a lot of info through the issues on the github. Right now switched to the other alternative editors, but possibly will get back to it in the future.
本文标签: javascriptrich text with non editable contentangularjsStack Overflow
版权声明:本文标题:javascript - rich text with non editable content, angularjs - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1743899741a2049151.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论