[英]Angular SCE trust HTML variable in rootScope function
我正在嘗試從Angular作用域函數傳遞一個變量,以使TinyMCE textarea
的HTML內容呈現在ng-bind-html
。 不確定為什么以下功能仍會出現$sce.unsafe
錯誤
rootScope
app.run(function($rootScope, $http, $sce, $compile) {
// Text Parsing
$rootScope.txtRefresh = function(obj) {
obj = $sce.trustAsHtml(obj);
};
});
調節器
$scope.txtRefresh = function (obj) {
$rootScope.txtRefresh(obj);
}
局部
<label>Paragraph 1</label>
<textarea data-ui-tinymce ng-change="txtRefresh(field['txt-1'])" type="text" class="form-control" ng-model="field['txt-1']" rows="4" placeholder="Description..." />
<div ng-bind-html="field['txt-1']"></div>
您應該調用該函數以直接在綁定中信任資源。 因此: txtRefresh(field['txt-w']
$ sce.trustAsHtml返回受信任的資源,它不會修改傳遞給它的字符串。 因此,您的ngChange沒有做任何有意義的事情。 您也可以在更改時調用一個函數,該函數信任field['txt-w']
並將其存儲在范圍中,然后讓ng-bind-html使用該新的受信任值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.