0

Javascript

<script>    
var car=[  
  {
   name:'honda',
   color:'red',
   comments:[
    {
     rating:3,
     bidprice:"25,000"
    },
    {
     rating:4,
     bidprice="21,000"
    ]
   }
  ];
</script>

What am i trying to do is getting the bid price of car from each comments by using ng-repeat. I did try like this

<li ng-repeat="car in carList">
  {{car.comments.bidprice}}
</li>

Unfortunately, I getting nothing respond from this code. What should I do? Thanks you.

4
  • Can you add your HTML that contains the ng-repeat to the question? Commented Nov 24, 2015 at 15:10
  • Sorry, just updated the ng-repeat. I am new to Angular JS. Commented Nov 24, 2015 at 15:12
  • comments is an array. You're going to have to ng-repeat over car.comments Commented Nov 24, 2015 at 15:17
  • so what you saying is using <li ng-repeat ="car.comments in carList"> rather than using <li ng-repeat="car in carList"> ? Commented Nov 24, 2015 at 15:29

2 Answers 2

1
<li ng-repeat="comment in car.comments">
  {{comment.bidprice}}
</li>

Should work. I am not sure where you took carList from.

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

2 Comments

<li ng-repeat="bidprice in car.comments"> {{bidprice.bidprice}} </li> are we able to do like this? I am not sure how to declare.
Yes that should work, but I would use 'comment' since you are looping through comments
0

comments is an array. or you do like this car.comments[0].bidprice or you do another ng-repat="comment in car.comments".

5 Comments

Yeah, i try car.comments[0].bidprice before but if i want using ng-repeat to get all the bid price rather than type two times car.comments[0].bidprice and car.comments[1].bidprice. Sorry for poor english.
vicky do you have one car with many comments that you want to display or do you have N cars and you want to display for each car its comments?
Yeah I only got one car with many comment and inside the comments got bidprice this attribute. I am trying to use ng-repeat to display all the bidprice.Thanks you.
vicky then, your car above is an array but it isn't right like this, so your car trasform in a object(var car={....}) and then try this: <li ng-repeat="comment in car.comments"> {{comment.bidprice}} </li>
Thanks you. I did try "comment in car.comments", its work well!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.