我有一个指令,根据ng-repeat
项目数据(来自数据库),使用开关盒构建自定义 HTML:
app.directive('steps', function($compile){
return {
'restrict': 'A',
'template': '<h3>{{step.name}}</h3><ul ng-repeat="opt in step.opts"><div ng-bind-html-unsafe="extra(opt)"></div></ul>',
'link': function($scope, $element){
$scope.extra = function(opt){
switch ($scope.step.id){
case 1:
return "<div>Some extra information<select>...</select></div>"
case 2:
return "<div><input type='checkbox' ng-model='accept'> Accept terms</div>"
case 3:
return "<div>{{step.title}}<select multiple>...</select></div>"
}
}
}
}
});
上面的代码有效,但函数内部的可绑定{{step.title}}
不起作用。我试过$compile(html)($scope)
了,但它给了我一个Error: 10 $digest() iterations reached. Aborting!
. 我该怎么处理这个?