0

I have a nested array:

$scope.audits = [{
    name: '2015', 
    sections:[{
    section:'mm',
    id:'1',
        subsections: [{
        subsection:'aa',
        mainelements: ['cc','dd']
        },{
        subsection:'bb',
        mainelements: ['ee','ff','gg']
        }]
    }]

}];

I want to have a few buttons to add and delete nested elements at will. I cannot use $index because it is multiple layers of array.

Here is my Plunker

3
  • you can add and delete elements with array.splice(), but you need an index. Commented Nov 15, 2015 at 10:11
  • to identify the right array you can use a second parameter at your remove function. Commented Nov 15, 2015 at 10:15
  • I just found out that I can use $parent.$index to get parent's index. I already updated my plunker Commented Nov 15, 2015 at 10:19

1 Answer 1

2

This problem got it's crazy solutions out here: AngularJS: traversing nested arrays . I'm not going to rewrite the solutions once again because it's unefficient. Don't forget to use search before asking a question.

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

Comments

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.