Raas Masood Raas Masood - 4 years ago 114
Javascript Question

ngresource not filtering properly with oData based Rest Controller

i have a web api based controller using MongoDb at back end.

public class NodesRestController : ApiController
{
private INodeService _nodeService;
public NodesRestController(INodeService nodeService)
{
_nodeService = nodeService;
}
[EnableQuery()]
public IQueryable<Node> Get()
{
return _nodeService.GetAllNodes().AsQueryable();
}
[EnableQuery()]
public Node Get(Guid id)
{
return _nodeService.GetNodeById(id);
}
}


in an angular application my resource looks like

(function() {
'use strict';
var nodeServiceRoot = '/api/NodesRest/:id';

angular.module('common.service')
.factory("nodeResource", ["$resource", "appSettings", nodeResource])

function nodeResource($resource, appSettings) {
return $resource(appSettings.serverPath + nodeServiceRoot, {
id: '@id'
}, {
"update": {
method: "PUT"
}
});
}}());


Nodes Collection looks like multiple instances such below.

{
"_id" : LUUID("982d248a-ef2a-f94c-be93-96ff67ca1d3f"),
"Name" : "RTR1",
"IP" : "1.2.221.121",
"NodeGroup" : {
"_id" : LUUID("36a38db3-830c-4a45-8b9c-63b16394f985"),
"Name" : "Group One"
}}


i am trying to get all the nodes where NodeGroup.Name = "Group One" but i get all the nodes back.

var nodesInNodeGroup = nodeResource.query({ 'NodeGroup/Name': vm.CurrJob.NodeGroup.Name});
nodesInNodeGroup.$promise.then(function (response) {
nodesInNodeGroup = response;
});


vm.CurrJob.NodeGroup.Name = 'Group One'

kindy help.

Answer Source

Your controller is not an ODataController.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download