I need to make an api call that returns me a response of id's and values associated with it. The promise then resolves and returns a true or false if the id queried was found or not found.
How can i achieve this? New to using promises. As is promises seem confusing
here is the end point on consuming the API, UserService returns an array of id's and salaries. I need to check if the id exists and the salary matches to the query and then the promise needs to resolve to true or false.
here is the object of id's and incomes
[{
"id": 1,
"name": "Primary",
"sal": [{
"id": "1",
"sal": "10"
}, {
"id": "2",
"sal": "20"
}]
},{
"id": 2,
"name": "Secondary",
"sal": [{
"id": "1",
"sal": "100"
}, {
"id": "2",
"sal": "200"
}
]
}];
UserService.hasUserValue(id, income).then(function(qualifiesforlowIncome){
var isLowIncome = qualifiesforlowIncome
}
qualifiesforlowIncome is a boolean that returns a true or false. I am using angular so in this case should i do a $q.defer and return a defer.promise ?
A little unclear on this
return
from thethen
callback the value that you need, and you've got your promise! – Ufo