I have a MEAN.JS application. The code below is my AngularJS controller, which runs a query to retrieve all articles in my MongoDB database.
public/modules/articles/controllers/articles.client.controller.js
angular.module('articles').controller('ArticlesController', ['$scope', '$location', '$stateParams', 'Authentication', 'Articles',
function($scope, $location, $stateParams, Authentication, Articles) {
...
// Find a list of Articles
this.articles = Articles.query();
...
}
]);
The query above is defined in the file and code below:
app/controllers/articles.server.controller.js
exports.list = function(req, res) {
Article.find().sort('created').populate('user', 'displayName').exec(function(err, articles) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(articles);
}
});
};
Articles.query()
seems to be linked to exports.list
. I want Articles.query()
to use a different export, let's say exports.anotherList
. How do I change this?
I have a feeling I have to define it somehow in the file app/routes/articles.server.routes.js
, but I cannot figure out how to make it work.
Thanks. I'll accept the answer that helps me solve this.