我在应用程序中使用MEAN stack,而AngularJS是我的前端。我怎样才能在重复的答案中删除Square Brackets []Double quotes "",实际上我们需要在我的应用程序中显示role的值,所以我们使用ng-repeat="mani in name.comments "来获得答案,我们得到了像["user"]["admin"]["kp"]这样的答案,我们所看到的只是单独显示值,而不是使用[] Square BracketsDouble quotes。。。。例如,答案是:-值没有in[] Square BracketsDouble quoteslike1. user , 2. admin, 3. kp
我的数据:-

$scope.name = {
"_id": "5863d3aaacaeddc00663bc07",

"comments": [
{
"created": 1485511936350,
"role": [
"user"
],
"email": "[email protected]",
"name": "selvam R",
"commentText": "mani selvam"
},
{
"created": 1485511936350,
"role": [
"admin"
],
"email": "[email protected]",
"name": "selvam R",
"commentText": "mani selvam"
},
{
"created": 1485511936350,
"role": [
"kp"
],
"email": "[email protected]",
"name": "selvam R",
"commentText": "mani selvam"
}
],
"created": "2016-12-28T15:00:58.777Z",
"isCurrentUserOwner": false
};

我的Html:-
<div ng-repeat="mani in name.comments ">

                <td>{{$index + 1}}</td>
                <td>{{mani.role }}</td>

              </div>

请查看My plunker以供参考。。。
预期答案是没有[] Square BracketsDouble quotes。。。
这个role在数组中,所以只有它用[] Square BracketsDouble quotes显示,所以我们如何删除它,我们只需要显示值。。。我们已经尝试了很多方法,我们知道这是一个简单的任务,但我们无法解决这个问题。。
我们可以用css删除这个吗?... 任何人都知道解决办法请帮助我们。。。谢谢
请更新plunker以及了解确切的解决方案。。。。

最佳答案

只需使用以下命令选择索引0处数组的第一个元素:
{{ mani.role[0] }}

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = {
    "_id": "5863d3aaacaeddc00663bc07",

    "comments": [{
      "created": 1485511936350,
      "role": [
        "user"
      ],
      "email": "[email protected]",
      "name": "selvam R",
      "commentText": "mani selvam"
    }, {
      "created": 1485511936350,
      "role": [
        "admin"
      ],
      "email": "[email protected]",
      "name": "selvam R",
      "commentText": "mani selvam"
    }, {
      "created": 1485511936350,
      "role": [
        "kp"
      ],
      "email": "[email protected]",
      "name": "selvam R",
      "commentText": "mani selvam"
    }],
    "created": "2016-12-28T15:00:58.777Z",
    "isCurrentUserOwner": false
  };
});

<!DOCTYPE html>
<html ng-app="plunker">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <script>
    document.write('<base href="' + document.location + '" />');
  </script>
  <link rel="stylesheet" href="style.css" />
  <script data-require="[email protected]" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.10/angular.min.js" data-semver="1.5.10"></script>
  <script src="app.js"></script>
</head>

<body ng-controller="MainCtrl">

  <div ng-repeat="mani in name.comments ">

    <td>{{$index + 1}}</td>
    <td>{{ mani.role[0] }}</td>

  </div>


</body>

</html>

09-05 07:53