2016-10-31 5 views
0

udestandに私を助けてください。 ng-repeatのキー値の配列を取得することはできません(blockquote)。コンソールには何も表示されず、エラーもありません。 これは私の変更されたコードです:Angularjs ng-repeat、キーで値の配列

<div class="row row-content" ng-controller = "DishDetailController"> 
    <blockquote ng-repeat="comment in dish"> 
    <p>{{comment.rating}} Stars</p> 
    <p>{{comment.comment}}</p> 
    <footer>John Lemon</footer> 
    </blockquote> 
</div> 

スクリプト:

angular.module('confusionApp', []) 
.controller('DishDetailController', ['$scope', function($scope) { 

var dish=[{ 
name:'Uthapizza', 
image: 'images/uthapizza.png', 
category: 'mains', 
label:'Hot', 
price:'4.99', 
description:'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.', 
comment: [ 
    { 
    rating:5, 
    comment:"Imagine all the eatables, living in conFusion!", 
    author:"John Lemon", 
    date:"2012-10-16T17:57:28.556094Z" 
    }, 
    { 
    rating:4, 
    comment:"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", 
    author:"Paul McVites", 
    date:"2014-09-05T17:57:28.556094Z" 
}, 
] 
} 
]; 

$scope.dish = dish; 

}]); 
+0

@swenあなたは残念ながら、それは動作しません答え – Sajeetharan

+0

を確認しました。質問コードを更新しました –

+0

コンソールでエラーが表示されていますか? – Sajeetharan

答えて

2

変更、

this.dish = dish; 

$scope.dish = dish; 

にそして、あなたのコントローラに$スコープ変数を注入し、

var app = angular.module('confusionApp', []); 
app.controller('dishDetailController', function($scope) { 
    var dish = [{ 
    name: 'Uthapizza', 
    image: 'images/uthapizza.png', 
    category: 'mains', 
    label: 'Hot', 
    price: '4.99', 
    description: 'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.', 
    comments: [{ 
     rating: 5, 
     comment: "Imagine all the eatables, living in conFusion!", 
     author: "John Lemon", 
     date: "2012-10-16T17:57:28.556094Z" 
    }, { 
     rating: 4, 
     comment: "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", 
     author: "Paul McVites", 
     date: "2014-09-05T17:57:28.556094Z" 
    }] 
    }]; 
    $scope.dish = dish; 
}); 

あなたはコメントをループにしたい場合は、ビューがあるべき、

<blockquote ng-repeat="comment in dish[0].comments"> 
    <p>{{comment .rating}} Stars</p> 
    <p>{{comment .comment}}</p> 
    <footer>John Lemon</footer> 
</blockquote> 

DEMO

+0

すべてのコメントまたは料理のコメントのサブセットを表示するには、内側のng-repeatを使用することをお勧めします。 – Ronald91

関連する問題