想要显示以逗号分隔的名称

时间:2016-03-28 10:35:49

标签: angularjs

这里是显示书详细信息的程序。一切都很完美,但我不知道如何显示以逗号(,)分隔的authorname。我想在主页中显示以逗号(,)分隔的作者姓名。第三行是错误。我想修复并显示authornames。

 home.html

    <script type="text/ng-template" id="display">
            <td>{{book.title}}</td>
      errorline:    <td>{{book.authorname}}</td>(Here i want to display author names separated by comma(,))
            <td>{{book.price}}</td>
            <td>
               <i class="material-icons"><button type="button" data-ng-click="editBook(book)">create</button></i>
            </td>
           <td><i class="material-icons"><button type="button" data-ng-click="deleteBook(book)">delete_forever</button></i></td>

        </script>

controllers.js

 $scope.online_bookauthors= 'data/bookauthors.js';
 $scope.loadbookauthorscadentials= function (file) {
    $http.get(file)
    .then(function (result) {
        $scope.bookauthorsresult=result;
        $scope.bookauthorslist=$scope.bookauthorsresult.data.bookauthorsdetails;

    })
 }

 $scope.loadbookauthorscadentials($scope.online_bookauthors);

bookauthors.js

{
    "bookauthors": {
        "Id": 1,
        "name": "Book Author Details"
    },
    "bookauthorsdetails": [{
        "bookid": 1,
        "title": "War and piece",
        "price": 100,
        "authors": [{
            "authorid": 1,
            "authorname": "Tolstoy"
        }, {
            "authorid": 2,
            "authorname": "Herman melville"
        }]

    }, {
        "bookid": 2,
        "title": "moby Dick",
        "price": 200,
        "authors": [{
            "authorid": 1,
            "authorname": "Tolstoy"
        }, {
            "authorid": 2,
            "authorname": "Herman melville"
        }, {
            "authorid": 3,
            "authorname": "Jane Austen"
        }]
    }],
    "selected": {}
}

1 个答案:

答案 0 :(得分:0)

<div ng-repeat="author in book.authors">{{ ($index !== book.authors.length-1) ? author.authorname+',' : author.authorname }}</div>