maybe you can solve if you write controller like this, and call function from with ng-init directive. i put example on link
<div ng-controller="AppCtrl" ng-app="myApp">
<div ng-init="showManu()"></div>
<div id="menu"></div>
</div>
var app = angular.module('myApp', []);
app.controller('AppCtrl', ['$scope','$http','$compile',function ($scope, $http, $compile) {
$scope.roots = [{
Folder_Name:'root1',
_id:'1',
parent:null
},{
Folder_Name:'root2',
_id:'2',
parent:null
},{
Folder_Name:'newrow',
_id:'9',
parent:'1'
},{
Folder_Name:'chirag',
_id:'3',
parent:'1'
},{
Folder_Name:'sumit',
_id:'4',
parent:'2'
},{
Folder_Name:'vikas',
_id:'5',
parent:'4'
}
];
$scope.showManu = function(){
angular.forEach($scope.roots, function(root){
if(root.parent == null){
var myEl = angular.element(document.getElementById('menu'));
var html = '<ul><li id="'+root._id+'" ><a ng-click="hideShow('+root._id+')">'+root.Folder_Name+'</a></li></ul>';
var element = $compile(html)($scope);
myEl.append(element);
}
})
var hideList = [];
$scope.hideShow = function(id){
if(hideList.indexOf(id)==-1){
getLi(id);
hideList.push(id);
}
else{
var classHide = document.getElementById(id);
var x = classHide.getElementsByTagName("ul")
console.log(x.length);
for(var i = x.length; i>=1; i--){
console.log(i);
classHide.removeChild(classHide.childNodes[i]);
}
hideList.splice(hideList.indexOf(id),1);
}
}
function getLi(root){
angular.forEach($scope.roots, function(r){
if(r.parent == root){
var myEl = angular.element(document.getElementById(r.parent));
var html = '<ul class="'+r.parent+'"><li id="'+r._id+'"><a ng-click="hideShow('+r._id+')">'+r.Folder_Name+'</a></li></ul>';
var element = $compile(html)($scope);
myEl.append(element);
}
})
}
}
}]);