Keep your menu data in JSON like
// here key in json object is your current url.
$scope.menus = {
"syllabus":[{name:"Chapters",url:"",class:"fa fa-folder-open"},{name:"Q&A",url:"url",class:"fa fa-folder-open"},{name:"syllabus 3",url:"url 1",class:"fa fa-folder-open"}],
};
$scope.sub_menus = [];
$scope.setSubMenu =function(menu){
$scope.sub_menus = $scope.menus[menu];
}
Call setSubMenu function whenever you change the route. pass your current route as an argument that will set the current page menu data in to sub_menus array. angular will render this automatically for you.
app.directive('subMenu', ['$compile', function($compile) {
return {
restrict: 'EA',
template: ' ',
compile: function() {
return {
post: function($scope) {
}
}
}
}
}]);
manpreet
Best Answer
2 years ago
Is there a good tutorial on how to create a menu in angularjs, the menu should only appear on few pages, for example:
My links in the sidemenu will have the projectID
And many others, the sidemenu will show in all that pages where a project id is selected.