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?

2
  • How do you use this isAdmin variable? $resourse returns a promise, not just plain value. Commented Sep 30, 2015 at 7: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. Commented Sep 30, 2015 at 7:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.