无法在 ng-repeat 中显示某些特殊字符
Cannot display some special chars in ng-repeat
我正在尝试在 ng-repeat 中显示对象数组。
这是对象数组
$scope.test = [
{
value1: "app\test\maintenance1",
value2: "other value1"
},
{
value1: "app\test\maintenance2",
value2: "other value2"
}
]
这里是 html:
<table>
<tbody>
<tr ng-repeat="item in test">
<td>{{item.value1}}</td>
<td>{{item.value2}}</td>
</tr>
</tbody>
<table>
我遇到的这个问题是 $scope.test.value1 中包含的 \t 和 \ 没有被渲染。
我不想手动转义字符(使用 \\t 和 \\),因为我将从 REST 服务接收此数组。
我搜索了几个小时都没有成功(试过 $sce)。
这是我遇到的问题的一个问题:https://plnkr.co/edit/AhJaNCOa0saGTSjh9u5H?p=preview
您面临转义序列问题,您需要使用额外的 \(反斜杠)转义每个特殊字符,这是您要在视图中打印的每个特殊字符的情况,试试这个(单击 运行查看输出的代码片段):
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>
我正在尝试在 ng-repeat 中显示对象数组。
这是对象数组
$scope.test = [
{
value1: "app\test\maintenance1",
value2: "other value1"
},
{
value1: "app\test\maintenance2",
value2: "other value2"
}
]
这里是 html:
<table>
<tbody>
<tr ng-repeat="item in test">
<td>{{item.value1}}</td>
<td>{{item.value2}}</td>
</tr>
</tbody>
<table>
我遇到的这个问题是 $scope.test.value1 中包含的 \t 和 \ 没有被渲染。
我不想手动转义字符(使用 \\t 和 \\),因为我将从 REST 服务接收此数组。
我搜索了几个小时都没有成功(试过 $sce)。
这是我遇到的问题的一个问题:https://plnkr.co/edit/AhJaNCOa0saGTSjh9u5H?p=preview
您面临转义序列问题,您需要使用额外的 \(反斜杠)转义每个特殊字符,这是您要在视图中打印的每个特殊字符的情况,试试这个(单击 运行查看输出的代码片段):
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>