Javascript 使用$sce.trustAsHtml呈现字符串返回未定义

Javascript 使用$sce.trustAsHtml呈现字符串返回未定义,javascript,html,angularjs,parsing,Javascript,Html,Angularjs,Parsing,我试图将一个字符串解析为一个字符数组,每个字符周围都有。提交解析的函数起作用,每个字符周围都有标记。 要分析的函数: app.controller('tableCtrl',function($scope,$sce) { //parse cron_format and edit each digit individually $scope.parse = function (cron_format){ var parsed = cron_format.split(

我试图将一个字符串解析为一个字符数组,每个字符周围都有
。提交解析的函数起作用,每个字符周围都有
标记。 要分析的函数:

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;
    }
});
app.controller('tableCtrl',函数($scope,$sce){
//解析cron_格式并分别编辑每个数字
$scope.parse=函数(cron_格式){
var parsed=cron_format.split(“”);
for(var i=0;i
我在
中得到的是以下字符串:

*/3,*,*,*,*,*,*

为什么
不渲染? 下面是我试图添加结果的表格:

    <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>

{{user(user_id)}
{{script(script_id)}
**{{parse(cron_格式)}**
模板:

<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>

{{user(user_id)}
{{script(script_id)}
**{{l}**

不清楚您在这里想做什么
parsed
是一个数组,但您试图将其传递给只对字符串进行操作的函数
$sce.trustAsHtml
。好的,所以我将最后两行更改为“$scope.parsedCron=$sce.trustAsHtml(parsed.toString());返回$scope.parsedCron;`结果是:
*/3,*,*,*,*,*,*
在中,同样不会结束。您不应该在函数中返回
$scope.parsedCron
。如果您只返回一个字符串值,并将其分配给controller.thx中任何位置的$scope属性以获取建议,而不是在何处以及如何进行渲染,则会更好。不,我正试图做完全相反的事情,不显示->渲染它
<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>