Al.s
Al.s

Reputation: 310

rendering string using $sce.trustAsHtml returns undefined

I'm trying to parse a string to a chars array, surrounding each char with <span></span>. the function to commit the parse works and each char is surround with the <span> tag. function to parse:

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;
    }
});

what I'm getting in the <td> its this string:

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

why won't the <span> render? here is the table where im trying to add the result:

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

Upvotes: 0

Views: 202

Answers (1)

Marcos Sandrini
Marcos Sandrini

Reputation: 450

app.controller('tableCtrl',function($scope) {

  $scope.letters = function(cron_format){
    return cron_format.split('');
  }
}});

The template:

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

Upvotes: 2

Related Questions