我能够将字符串分解为字符数组并将每个字符包围在其中,<span></span>
但是当我尝试将此数组传递给表时,html 不会呈现。断弦:
//parse cron_format and edit each digit individually
$scope.parse = function (cron_format){
var parsed = cron_format.split('');
for(var i = 0; i < parsed.length; i++) {
parsed[i] = '<span>' + parsed[i] + '</span>';
}
return parsed;
}
当我尝试像这样创建表时:
<table class="table table-bordered table-hover">
<thead>
<td>user name</td>
<td>script name</td>
<td>cron format</td>
</thead>
<tbody ng-repeat="(user_id,script_id) in data | filter: test">
<tr ng-repeat="(script_id, cron_format) in script_id">
<td>{{user(user_id)}}</td>
<td>{{script(script_id)}}</td>
<td ng-bind-html-unsafe="{{parse(cron_format)}}"></td>
</tr>
</tbody>
</table>
cron_format 中没有值:
不尝试渲染-><td>{{parse(cron_format)}}</td>
表格如下所示: 我做错了什么?
更新:
我改变了函数的最后两行:
$scope.parsed.htmlSafe = $sce.trustAsHtml(parsed.html);
return parsed;
我得到这个错误:
Can't interpolate: {{parse(cron_format)}}
TypeError: Cannot set property 'htmlSafe' of undefined
有人可以解释我在这里犯了什么错误吗?