1

I have a rest api which returns true/false, i called my rest api in postman and it works and it returns true or false. I need to call this service in angularjs, what change should i do in my angular js to make it return true/false, beacause now it returnsobjewct object.

function checkIsActive() {            
    return $resource('http://localhost:8080/myservice/v1/testService').query().$promise;
}

1 Answer 1

2

For APIs that return boolean values, use the $http service:

function checkIsActive() {            
    return $http.get('http://localhost:8080/myservice/v1/testService');
}

The $resource service returns arrays for the .query action method and objects for the .get action method.


when i have console.log(myService.checkIsActive()); then it print [object Object] still it does not return boolean.

Keep in mind that the service returns a promise from which the data needs to be extracted:

var promise = myService.checkIsActive();
promise.then(function(response) {
    console.log(response.data);
};
Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your answer, i changed my code to use $http.get as you mentioned above. and now when i have console.log('this is test service ' + myService.checkIsActive()); then it print ' this is test service [object Object]' still it does not return boolean.
The boolean needs to be extracted from the promise. See update to answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.