I'm learning the MEAN stack. I have a node api hooked up to MongoLab hosted DB.
The api returns objects like this (api/messages
):
[
{
_id: "55074ce3c21903c9cce6d02a",
name: "some random message",
__v: 0
},
{
_id: "55074e4a1dad546fcef09769",
name: "a different message",
__v: 0
},
{
_id: "55074e4a1dad546fcef09123",
name: "bingo",
__v: 0
}
]
With restangular, I get the data and then bind to $scope
:
Restangular.all('api/messages').getList().then(function (data){
$scope.messages = data;
});
In one part of the app, I want to query/return only necessary data - something like this:
Restangular.all('api/messages').customGET('', {"q": {"name": "a different message" }}).then(function (data) {
console.log(data);
});
I want to only return objects that contain X - in this case, 'a different message'.
However, the customGET
method doesn't seem to work as I expect; I always get all of the objects.
How can I achieve this? I've been searching and trying things out for a while with no success. Maybe I need to add some api routes and methods.
Any help would be v.appreciated :)