Recently delving into Angular development, I've found myself caught in a loop trying to solve this particular issue.
To give some context, I'm utilizing the MEAN stack through mean.io which includes Angular UI Router functionalities.
In my database, there is a Post model that can be associated with a category ID.
For new posts, I aim to fetch existing categories from the database and present them in a select box.
My understanding suggests that using resolve is necessary. However, it feels odd to embed logic within the resolve property located in a file named config.js. Currently, I've included the service call there and retrieved the categories using this code snippet:
.state('create post', {
url: '/posts/create',
templateUrl: 'views/posts/create.html',
controller: 'PostsController',
resolve: {
loadCategories: function (Categories) {
Categories.query(function(categories) {
return categories;
});
}
}
})
The initial hurdle is accessing the returned data in either my controller or view.
Additionally, I specifically want to retrieve categories tied to a particular Organization. Each user will have an organization ID, so how do I access the details of the currently signed-in user from within the config.js file? This location seems unfit for handling such complex logic.
I would greatly appreciate any assistance on this matter.
Thank you