Just getting started with MEAN.io and they include a sample "articles" model that resembles a typical blog post with a title and body.
Included in the example is an index.html
file that showcases a list of articles upon navigation. Within this file, there's a call to a find
method defined in the public controller like so:
$scope.find = function() {
Articles.query(function(articles) {
$scope.articles = articles;
});
};
I came across a server controller that contains the following method definition:
/**
* List of Articles
*/
exports.all = function(req, res) {
Article.find().sort('-created').populate('user', 'name username').exec(function(err, articles) {
if (err) {
return res.json(500, {
error: 'Cannot list the articles'
});
}
res.json(articles);
});
};
By adding a constraint to the find
method in the server controller, I found that I could specify where
filters for the query, resulting in changes reflected in the view.
Is there an inherent connection between these two controllers that the framework manages behind the scenes? I've been unable to locate any information detailing their relationship.