First of all, I'm not very good at angles.
While I was studying around $ q, I ran into some strange problem.
When I use $ q.all, I put $ http in a regular sequence, expecting to get the results in the same order
but I get random results.
Look at this and correct my stupidity.
$q.all([
HttpService.editItem(
$scope.$parent.category_id,
Define.CAR_CAT,
$scope.car_id,
{car_name: inputValue.toUpperCase()}
),
HttpService.getCarList(
$scope.$parent.category_id,
Define.CAR_CAT
)
]).then(function (results) {
if (results[0].statusText === 'OK' && results[1].statusText === 'OK') {
.....
});
"HttpService" is the service of my application. He returns the promise.
I expected
First change the name of the car, then get a list of cars.
But the results that I got, first got a list of cars, then changed the name of the car.
And I use
return $ q (function (resolution, rejection) {});
instead
$ q.defer ();
.
.
.
.
and this is my part of the HttpService
function editItem(cat_id, cat_url, content_id, item_data) {
return $q(function (resolve, reject) {
$http({
method: 'PUT',
url: Define.TEST_URL + cat_id + cat_url + content_id,
data: item_data
}).then(function (response) {
resolve(response);
}, function (error) {
reject(error);
});
});
}
function getCarList(cat_id, cat_url) {
return $q(function (resolve, reject) {
$http({
method: 'GET',
url: Define.TEST_URL + cat_id + cat_url
}).then(function (response) {
resolve(response);
}, function (error) {
reject(error);
});
});
}
and here is the answer getCarList
{
"error_msg": "",
"error_num": 0,
"statusText": "OK"
"results": [
{
"car_id": "CAR0121",
"car_name": "AUDI R8"
},
{
"car_id": "CAR0122",
"car_name": "AUDI A6"
},
{
"car_id": "CAR0128",
"car_name": "BENZ"
},
{
"car_id": "CAR0130",
"car_name": "PORCHE"
},
]
}