In the menus.client.service.js file I'm trying to understand the structure of how the menus in the MEAN.js framework is populated
The code starts out with an empty menus object assigned to this
this.menus = {}
and then at the bottom of the file, this.addMenu('topbar') function is called
// Add new menu object by menu id
this.addMenu = function(menuId, isPublic, roles) {
console.log('pre-this.menus')
console.log(this.menus) // empty object
// Create the new menu
this.menus[menuId] = {
isPublic: isPublic || false,
roles: roles || this.defaultRoles,
items: [],
shouldRender: shouldRender
};
console.log('post-this.menus')
console.log(this.menus[menuId]) //complete populated menu with submenus i.e "List Articles", "New Article"
// Return the menu object
return this.menus[menuId];
};
Through this one function, it seems like two other functions are called
this.addMenuItem and this.addsubMenuItem
But I don't know how it happened because I don't see them explicitly called in the file.
I think I'm missing an important concept here. I also looked at the header.client.controller.js file, but all it does is call the getMenu function and assign to $scope.menu
$scope.menu = Menus.getMenu('topbar');
Here is the full nonfunctional file code
jsfiddle: http://jsfiddle.net/4c5gc0aq/