0

I am fairly new to AngularJS and trying to get data via $resource in my service.

vetoApp.service('adminKeyService', ['$resource', function($resource) {
this.IsAdmin = function(key) {
    var vetoAPI = $resource("http://localhost/mcspro/veto/api/getadminkey/", { callback: 'JSON_CALLBACK'}, { get: { method:'GET' } } );
    return vetoAPI.get({ k: key});
}
}]);

My api call returns this simple JSON data:

{
  "isAdmin": false
}

depending to the value of key. Now, in controller when I call this service, I get something like

d {$promise: d, $resolved: false} $promise: d $resolved: true isAdmin: false __proto__: d

My controller has following code to call the service and log it in console:

var isAdmin = adminKeyService.IsAdmin($scope.adminkey);
console.log(isAdmin);

How would I get isAdmin value from this object?

jsan
  • 177
  • 1
  • 2
  • 14
  • How do you use this `isAdmin` variable? $resourse returns a promise, not just plain value. – raina77ow Sep 30 '15 at 07:19
  • that was the problem that i was getting the promise and how to get value from promise. The post you mentioned solved the issue, thanks. – jsan Sep 30 '15 at 07:37

0 Answers0