<div ng-app="Example"> <div ng-controller="TestController"> <ul> <li ng-repeat="item in list"> <span>{{item.name}}</span> <button ng-click="add(item)">Add</button> <ul ng-show="item.children"> <li ng-repeat="child in item.children"> <span>{{child.name}}</span> </li> </ul> </li> </ul> </div> </div>
angular.module('Example', []).controller('TestController', [ '$scope', function ($scope) { $scope.list = [ { name : 'Example 1' }, { name : 'Example 2' }, { name : 'Example 3' } ]; $scope.add = function (item) { item.children = (item.children || []); var count = item.children.length + 1; item.children.push({ name : 'Child ' + count }) }; } ]);