如何将html视图插入框中?从id test1到vm.input变量?
angular.js:13920 Error: [$sce:itype] Attempted to trust a non-string value in a content requiring a string: Context: html
控制器:
vm.showbox = function(name) {
console.log("testing name " + name);
var a = angular.element('#' + name)[0];
console.log(a);
vm.inputbox = $sce.trustAsHtml(a);
console.log(vm.inputbox);
};
视图:
<div class"click" ng-click="vm.showbox('test1')">click/div>
<div id="test1" class="ng-hide">
<h3>Shema</h3>
schema here.
</div>
<div style="display: block;" ng-bind-html="vm.inputbox ">
</div>
控制台日志:
<div id="test1" class="ng-hide">
<h3>Shema</h3>
schema here.
</div>
angular.js:13920 Error: [$sce:itype] Attempted to trust a non-string value in a content requiring a string: Context: html
最佳答案
app.filter('trustFilter', ['$sce', function($sce){
return function(text) {
return $sce.trustAsHtml(text);
};
}]);
您应该为此使用过滤器。并做了一些更改,喜欢
<div style="display: block;" data-ng-bind-html="inputbox | trustFilter">
并且在您的控制器中
vm.inputbox = name;
$ sce.trustAs需要一个字符串值。也许会有所帮助(y)