3
In index.html I have 2 views:
- sidebar-left : where the menu is loaded after login.
- content : where the page in question is loaded
I am using angular-ui-router and after login, the user is redirected to Dashboard.
On the Dashboard is done the sidebar-left loading:
.state('dashboard', {
url: "/dashboard",
views: {
'content': {
templateUrl: 'view/dashboard.html',
resolve: {
auth : function ($q, Session) {
var userInfo = Session.getUserInfo();
if (userInfo) return $q.when(userInfo);
else return $q.reject({ authenticated: false });
}
},
controller: 'dashboard'
},
'sidebar-left' : { templateUrl: 'view/sidebar-left.html', controller: 'menu' }
},
})
It turns out the sidebar-left is common on all pages, when switching from Dashboard to another area the sidebar disappears.
This I decided to add on all routes the view "sidebar-left".
It turns out that the "sidebar-left" view is associated with a controller that does a GET to the server and PHP reads the database and returns the menu.
Every time I change the route, this controller runs an unnecessary GET to the server.
The problem is the logic used, as I do for the menu to be loaded only once?