0

Please help me to udestand. I can't to get an array of key value for ng-repeat (in blockquote). Nothing is displayed and no errors in console. This is my changed code:

<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>

Script:

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;

 }]);
7
  • @swen did you check the answer Commented Oct 31, 2016 at 18:31
  • Unfortunatly it does not work. I updated the question code Commented Oct 31, 2016 at 19:13
  • are you seeing any error in console? Commented Oct 31, 2016 at 19:17
  • no, there are no errors Commented Oct 31, 2016 at 19:19
  • can i get team viewer? Commented Oct 31, 2016 at 19:20

1 Answer 1

2

Change,

 this.dish = dish;

to

$scope.dish = dish;

And inject $scope variable to your controller,

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;
});

If you want to loop over the comments, the view should be,

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

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

Might be best to have an inner ng-repeat to display all the comments or a subset of the comments for a dish.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.