Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How do you access an object within an array within a json object using AngularJS's ng-repeat?

Also, if you have an edit button copied on each row of a table (using ng-repeat), how do you disable the other button copies when one button is clicked?

Here is my code: http://plnkr.co/edit/VNuVLrtadJ2gyOr3AeoX?p=preview

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Disabling editing for other elements is pretty easy. You just need to add a flag to the parent scope which says an element is being edited:

$scope.editing = false
$scope.toggleEdit = function(){
  $scope.editing = !$scope.editing;
}

And then make your ng-show or ng-hide something like ng-hide="editMode || $parent.editing.

You can toggle the edit mode using the toggleEdit function:

ng-click="editMode = true; toggleEdit()"

To solve your second problem, you need to reference the item in the array you want to get access to. You can achieve this with the Arrays indexOf function:

var index = rows._embedded.alternate.indexOf(shift)
rows._embedded.alternate[ index]._embedded.event.distance

Here's your plunkr, updated to work with the above: http://plnkr.co/edit/ZwHpN5MFpS2c1VFjLckU

share|improve this answer
1  
Thanks so much! It works perfectly! –  kimli Mar 6 '14 at 21:40

You might want to try a second nested loop. Say, within this ng-repeat:

<tr ng-repeat="rows in table._embedded.events">

have another ng-repet for altRows in rows._embedded.alternate

<span ng-repeat="altRows in rows._embedded.alternate">...</span>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.