[英]How to use ng-bind-html with two-way databinding?
I'm currently working on a simple editor built with angular. 我目前正在研究一个用angular构建的简单编辑器。 The main textbox is just a div with the contenteditable set to true and the ng-bind-html attribute, like this:
主文本框只是一个div,其中contenteditable设置为true和ng-bind-html属性,如下所示:
<div contenteditable="true" ng-bind-html="field.content">HTML content here</div>
The value is set and rendered properly with the right tags and look at page load. 使用正确的标记设置和正确呈现该值并查看页面加载。 But since it's only bound one way I my data or model isn't updated upon edit.
但由于它仅限于一种方式,我的数据或模型在编辑时不会更新。
I've tried some contenteditable directivs but most of them requires ng-model, but if I add that my html tags are not rendered and converted into symbols. 我已经尝试了一些可疑的方法,但大多数都需要ng-model,但如果我添加我的html标签不会被渲染并转换成符号。
EDIT: Just using this temporary "fix" for the time being, but I would like something more robust. 编辑:暂时只使用这个临时“修复”,但我想要更强大的东西。
<div contenteditable="true" ng-bind-html="field.content"
ng-blur="saveHTML($event)"></div>
$scope.saveHTML = function(event) {
this.field.content = event.target.innerHTML;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.