使用$se.trustAsHtml呈现字符串返回未定义的结果

rendering string using $sce.trustAsHtml returns undefined

本文关键字:返回 未定义 结果 字符串 se trustAsHtml 使用      更新时间:2023-09-26

我试图将一个字符串解析为一个字符数组,用<span></span>包围每个字符。提交解析的函数起作用,并且每个字符都被CCD_ 2标签包围。要解析的函数:

app.controller('tableCtrl',function($scope,$sce) {
    //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>';
        }
    $scope.parsedCron = $sce.trustAsHtml(parsed.toString());
    return $scope.parsedCron;
    }
});

我在<td>中得到的是这个字符串:

<span>*/3</span>,<span>*</span>,<span>*</span>,<span>*</span>,<span>*</span>

为什么<span>不渲染?这是我试图添加结果的表格:

    <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>{{parse(cron_format)}}</td>**
        </tr>
    </tbody>
app.controller('tableCtrl',function($scope) {
  $scope.letters = function(cron_format){
    return cron_format.split('');
  }
}});

模板:

<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><span ng-repeat="l in letters(cron_format)">{{l}}</span></td>**
    </tr>
</tbody>