Currently I am working on a project using AngularJS and I need to create a directive which is able to display (and alter) a "recursive structure" - something similar to a family. The structure defined in the controller looks like this:
$scope.members = [
{ firstName: 'Andrei', lastName: 'Croitoriu', age: 32 },
{ firstName: 'John', lastName: 'Doe', age: 25, members: [
{
firstName: 'Jane', lastName: 'Doe', age: 24
}
]}
];
I've managed to implement the directive which display the structure, but now I am struggling to implement a "Add Member" feature. Basically for each member I want to have a button next to it and be able to add a new member to the node. I would like to have a single method defined in the controller - all my attempts so far failed so in the plnkr code attached I've removed all attempts (left just a simple addMember method which just adds a new member to the top level collection.
Can anybody suggest any idea on how to pass the addMember method to the directives and implement the behavior I expect?
My code can be found here: http://plnkr.co/edit/hRzQiW?p=info
Thank you in advance!
Andrei
addMemberfunction in isolated scope