HTML不会使用ng-bind-html-unsafe呈现

时间:2015-02-10 11:22:48

标签: html angularjs ng-bind-html

我能够将字符串分解为chars数组并围绕<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中没有值: enter image description here 不试图渲染 - &gt; <td>{{parse(cron_format)}}</td>

表格如下: enter image description here 我做错了什么?

更新

我改变了函数的最后两行:

$scope.parsed.htmlSafe = $sce.trustAsHtml(parsed.html);
return parsed;

我收到此错误:

Can't interpolate: {{parse(cron_format)}}
TypeError: Cannot set property 'htmlSafe' of undefined

有人可以解释我在这里做的错误吗?

0 个答案:

没有答案