Hey there, I'm diving into the world of Angular and I've been struggling for the past couple of days trying to figure out a solution for this issue. Not entirely sure if my approach is right either.
My goal is to create a simple page with a dynamic menu. When a user clicks on a menu link, the corresponding view should load below the menu without refreshing the entire page. Sounds straightforward, right?
However, here's the catch - I need to have separate menus for admins and regular users, which are loaded through ajax. Here's a snippet of what I'm dealing with:
[
{
name: "Manage games",
templateUrl: "/view/mygames.html",
url: "/games",
},
{
name: "Weekly Reports",
templateUrl: "/view/myreports.html",
url: "/reports"
},
{
name: "Manage Users",
templateUrl: "/view/users.html",
url: "/users",
adminRequired: true
}
];
Once the menu is loaded, clicking on a menu item should trigger an ajax call to fetch data from the specified url
, while the template to display this data will also be fetched via an ajax call to the templateUrl
.
So, how can I achieve this? Essentially, I want to have a directive/component that starts off empty and hidden by default. When a menu item is clicked, I plan to $broadcast an event containing the dataUrl/templateUrl to the directive/component, prompting it to make two ajax calls - one for retrieving the data and another for fetching the template. Once both requests are complete, the content will render and become visible on the page.
Any suggestions or guidance on accomplishing this would be really helpful.
Just a heads up, I'm working with Angular 1.5.7