0

i have an angular application that calls web api . it was working all fine with web api controller and ngresource until i required to get count of results.

to get just the count of a result i need to use $inlinecount which only seems to be working with oDataController . with oDataControlelr in place my promises dont work.

$scope.totalCount = storeCommandResource.query({ $inlinecount: "allpages", $top: 0 });

i get

Error: [$resource:badcfg] query

please guide.

Raas Masood
  • 1,475
  • 3
  • 23
  • 61
  • I think you haven't pasted the full error message. But what is probably happening is that you are using the resource's `query()` method which expects to receive an array as a response. I'm assuming the response you're getting is just a number (or an object that contains the count), and not an array. If that's true, don't use the `query()` function, use the `get()` function instead: `storeCommandResource.get()` ... – Sunil D. May 28 '15 at 20:50
  • i get error like Error: [$resource:badcfg] get http://errors.angularjs.org/1.2.22/$resource/badcfg?p0=object&p1=array at http://localhost:7251/Scripts/angular.js:78:12 at e.(anonymous function).q.then.p.$resolved (http://localhost:7251/Scripts/angular-resource.min.js:9:330) at deferred.promise.then.wrappedCallback (http://localhost:7251/Scripts/angular.js:11546:81) at deferred.promise.then.wrappedCallback (http://localhost:7251/Scripts/angular.js:11546:81) at http://localhost:7251/Scripts/angular.js:11632:26 at Scope.$eval (http://localhost:7251....................... – Raas Masood May 29 '15 at 12:48

1 Answers1

0

its look like i can use oDatacontroller with a model builder setup like this

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntitySet<StoreCommand>("StoreCommandsRest");
        config.Routes.MapODataServiceRoute(routeName: "OData", routePrefix: "api", model: builder.GetEdmModel());
        config.AddODataQueryFilter();

and all i needed to change was query to get

$scope.totalCount = storeCommandResource.get({ $inlinecount: "allpages", $top: 0 });

then i am reading my returned count like

response["odata.count"]
Raas Masood
  • 1,475
  • 3
  • 23
  • 61