2

I am trying to display an array of objects inside an ng-repeat.

Here is the array of objects

$scope.test = [
    {
        value1: "app\test\maintenance1",
        value2: "other value1"
    },
    {
        value1: "app\test\maintenance2",
        value2: "other value2"
    }
]

Here is the html:

<table>
    <tbody>
        <tr ng-repeat="item in test">
            <td>{{item.value1}}</td>
            <td>{{item.value2}}</td>
        </tr>
    </tbody>
<table>

This issue I have is that the \t and \ contained in $scope.test.value1 are not rendered.

I don't want to escape chars manually (using \\t and \\) because I will receive this array from a REST service.

I searched for hours without success (tried $sce).

Here is a plunker of the issue I have : https://plnkr.co/edit/AhJaNCOa0saGTSjh9u5H?p=preview

Jerebenz
  • 45
  • 7

1 Answers1

1

You are facing escape sequence issue, you need to escape every special character with additional \ (backslash), this is the case with every special character you want to print on view, try this (click run code snippet to see the output) :

angular.module('mainMod', []).controller('mainController', function($scope){

$scope.test = [
    {
        value1: "app\\test\\maintenance1",
        value2: "other value1"
    },
    {
        value1: "app\\test\\maintenance2",
        value2: "other value2"
    }
]

})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js"></script>
<html ng-app="mainMod">

<head> </head>
<body ng-controller="mainController">

<ul>
  <li ng-repeat="item in test">
      {{item.value1}}  {{item.value2}}
  </li>

</ul>

</body>
</html>
Junaid Sarwar
  • 189
  • 1
  • 13