注意すべき点がいくつかあります。
コメントをjsonの配列に変更しました。何らかの理由で、あなたはそれをオブジェクトとして持っていました。
フィルタを使用しlimitTo
て、最後の 3 つに制限できます。 <li ng-repeat="message in item.comments | limitTo:-3"></li>
私の答えには、合計および機能しているコメントの追加が含まれます。
コントローラーコード:
myApp.controller('ItemController', function($scope, $route, $location, $http, Items){
Items.get(function(response){
$scope.items = response;
})
$scope.$watch('items', function() {
$scope.total = $scope.items[0].comments.length;
});
$scope.addMessage = function(mess) {
$scope.items[0].comments.push(
{
"name":"user1",
"description": "This is comment " + ($scope.total + 1)
}
);
}
})
Plunkr の更新: http://plnkr.co/edit/2oWLRU06Kdp0yKqjodmv?p=preview