Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS指令,模板具有ng repeat和ng bind html_Javascript_Angularjs_Angularjs Directive - Fatal编程技术网

Javascript AngularJS指令,模板具有ng repeat和ng bind html

Javascript AngularJS指令,模板具有ng repeat和ng bind html,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs 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

我已经创建了一个
指令
,模板有
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: '='
    }
};
});
app.directive('customField',函数($compile){
var getTemplate=函数(customType){
返回“”;
}
变量链接器=函数(范围、元素、属性){
html(getTemplate(scope.custom.type)).show();
$compile(element.contents())(范围);
}
返回{
限制:“E”,
代表1:是的,
链接:链接器,
范围:{
自定义:'='
}
};
});
但这会产生错误:
错误:[$sce:unsafe]试图在安全上下文中使用不安全值


在正常情况下,我使用
$sce.trustAsHtml(html\u代码)
来解决此类问题,但在指令中使用
ng repeat
如何解决此问题?

将$sce.trustAsHtml()绑定为作用域函数并调用它?或使用
ngSanitize
!谢谢你的建议。现在它开始工作了。谁的建议?碧溪的还是我的?:)两种解决方案都很好,但我使用了Bixi,因为我不想再添加一个js'angular sanitize.js'D