Angular: Empty Fiddle
http://angularjs.org/
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.2/angular.min.js"></script>
<script type="text/ng-template" id="tree_item_renderer.html">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{data.name}}</a>
<ul class="dropdown-menu">
<li ng-if="data.nodes.length != 0" class="menu-item dropdown dropdown-submenu" ng-repeat="data in data.nodes" ng-include="'tree_item_renderer.html'"></li>
<li ng-if="data.nodes.length == 0" class="menu-item" ng-repeat="data in data.nodes" ng-include="'tree_item_renderer.html'"></li>
</ul>
</script>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display: block; position: static; margin-bottom: 5px; *width: 180px;">
<li class="menu-item dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Menu<b class="caret"></b></a>
<ul class="dropdown-menu" ng-app="Application" ng-controller="TreeController">
<li class="menu-item dropdown dropdown-submenu" ng-repeat="data in tree" ng-include="'tree_item_renderer.html'"></li>
</ul>
</li>
</ul>
CSS
.dropdown-submenu {
position: relative;
}
.red{
color:red;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px 6px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #ffffff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
-webkit-border-radius: 6px 0 6px 6px;
-moz-border-radius: 6px 0 6px 6px;
border-radius: 6px 0 6px 6px;
}
JavaScript
angular.module("myApp", []).
controller("TreeController", ['$scope', function($scope) {
$scope.delete = function(data) {
data.nodes = [];
};
$scope.add = function(data) {
var post = data.nodes.length + 1;
var newName = data.name + '-' + post;
data.nodes.push({
name: newName,
nodes: []
});
};
$scope.tree = [{
name: "Level1",
nodes: [{
name: "Link1",
nodes: []
}, {
name: "Level2",
nodes: [{
name: "Link3",
nodes: []
}, {
name: "Level3",
nodes: [{
name: "Link4",
nodes: []
}]
}]
}]
}];
}]);