带有ng-repeat和ng-bind-html的模板的AngularJS指令

时间:2014-08-01 07:12:40

标签: javascript angularjs angularjs-directive

我创建的directive模板包含ng-repeatng-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的指令中如何解决此问题?

0 个答案:

没有答案