我创建的directive
模板包含ng-repeat
和ng-bind-html
,如下所示
app.directive('customField', function ($compile) {
var getTemplate = function (customType) {
return '<span ng-repeat ="option in custom.options" ng-bind-html="option"></span>';
}
var linker = function (scope, element, attrs) {
element.html(getTemplate(scope.custom.type)).show();
$compile(element.contents())(scope);
}
return {
restrict: "E",
rep1ace: true,
link: linker,
scope: {
custom: '='
}
};
});
但这会给出错误:
Error: [$sce:unsafe] Attempting to use an unsafe value in a safe context
。
在正常情况下,我使用$sce.trustAsHtml(html_code);
来解决此类问题,但在使用ng-repeat
的指令中如何解决此问题?