I have a problem with Jquerymetis menu. I want to load menu elements from Database and I'm using AngujarJS controller to get the JSON with menu elements.
Here is AngularJSController
var appControllers = angular.module('appControllers', []);
appControllers.controller('MenuCtrl', ['$scope', '$http',
function ($scope, $http) {
var url = "/api/Menus/GetMenuElements";
$http.post(url).
success(function (data, status, headers, config) {
$scope.menuElements = data;
console.log("Success");
}).
error(function (data, status, headers, config) {
console.log("Error");
});
}]);
Then in a PartialView of my ASP.NET MVC project I have the Angular directives to add the elements to menu.
<ul class="nav" id="side-menu">
<li ng-repeat="elementL1 in menuElements" ng-init="menuElements != null">
<a ng-if="elementL1.LINK !== null" href="{{elementL1.LINK}}"><i class="fa fa-home"></i> <span class="nav-label">{{elementL1.NAME}}</span><span class="fa arrow"></span></a>
<a ng-if="elementL1.LINK == null"><i class="fa fa-home"></i> <span class="nav-label">{{elementL1.NAME}}</span> </a>
<ul ng-repeat="elementL2 in elementL1.ChildMenu" ng-if="elementL1.ChildMenu.length > 0" class="nav nav-second-level">
<li class="primerLi">
<a>{{elementL2.NAME}}<span class="fa arrow"></span></a>
<ul ng-if="elementL2.ChildMenu.length > 0" class="nav nav-third-level">
<li ng-repeat="elementL3 in elementL2.ChildMenu">
<a href="{{elementL3.LINK}}">{{elementL3.NAME}}</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
This is adding fine the elements to the menu but it doesn't work the collapse and expand. It apear expanded and I can't collapse the elements.
I think that the problem is that I have to call $('#side-menu').metisMenu();
after loading elements but if i call this on the browser console it doesn't work.
How can achieve this? I'm new with Angular. Here I have seen the same issue but I could't solve the problem. https://github.com/onokumus/metisMenu/issues/22