1

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

2 Answers 2

1

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

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

Comments

0

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.