Here is demo: https://jimliu.github.io/angular-ui-tree/ but what about the situation when You delete all of the current nodes and You want to create the very first node?
So far I've got something like this:
<a href="" ng-click="createFirstChapterInput()"><span class="glyphicon glyphicon-circle-arrow-right"></span> New chapter</a>
<div class="row">
<div class="col-lg-12">
<div ui-tree id="tree-root">
<ol ui-tree-nodes ng-model="chapters">
<li ng-repeat="chapter in chapters" ui-tree-node ng-include="'nodes_renderer'"></li>
</ol>
</div>
</div>
The nodes_renderer is a template, taken exactly from the demo. It's too long to paste it here. Generally speaking - it shoud take this template and compile it in function.
Here is the createFirstChapterInput
function:
$scope.createFirstChapterInput = function() {
$scope.chapter = {};
Restangular.copy({route: Chapters.url}, $scope.chapter);
$scope.chapter['name'] = null;
var result = $('<li>' + $('#nodes_renderer').html() + '</li>');
$('#tree-root').find('ol').prepend(result);
$compile(result)($scope);
result.find('input.new').focus();
}
But well, it ends up on an error :
Controller 'uiTreeNode', required by directive 'uiTreeHandle', can't be found!
I don't know how to pass this controller to scope so compile would see it. Also I'm not sure whether the code is proper for this or is there any better solution.