In my AngularJS controller, I am sending an HTTP request to an API. The API can respond with either res.json(true)
or res.json(false)
depending on a certain condition.
However, it seems like the controller is not handling this as expected. I am interested in seeing how someone else might approach this:
function MyCtrl($scope, $http) {
$http.get('/api/call').
success(function(data, status, headers, config) {
console.log(data); // --> This outputs false
if (data) { // --> Here, I would expect this to fail, but it does not
console.log("true"); // --> This also gets displayed
}
});
- Should I change the response from the API so that it returns something different than res.json(false)?
- Should I update the code above to check for
if (data === false)
instead?