 |
|
เราต้องการจะทำตัว Loading ในระหว่างที่มีการร้องขอข้อมูล เมื่อร้องขอข้อมูลสำเร็จตัว Loading จะหายไป พอจะมีวิธีไหนบ้างคะ (ในตอนนี้เราใช้วิธีตั้ง timeout ให้หายไปเมื่อครบ 5000ms)
factory (JavaScript)
.factory('getproductService', ['$http', function($http) {
return {
getProduct: function(oClient) {
return $http({
url: base_url_websv + '/Get_Product',
method: 'POST',
data: $.param({
oClient: oClient
}),
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}
}).then(function successCallback (response) {
return response;
}, function errorCallback (response) {
return response;
})
}
};
}])
Controller (JavaScript)
.controller('productController', ['$scope', '$ionicLoading', '$timeout', 'getproductService', function($scope, $ionicLoading, $timeout, getproductService) {
$ionicLoading.show({
template: '<ion-spinner icon="ios"></ion-spinner>'+'<p>Loading . . .</p>',
animation: 'fade-in',
showBackdrop: true,
hideOnStateChange: true,
delay: 0,
});
$timeout(function () {
$ionicLoading.hide();
getproductService.getProduct(oClient).then(function(response) {
x2js = new X2JS();
var objProduct = x2js.xml_str2json(response.data);
$scope.product = objProduct;
});
}, 5000);
}])
Tag : JavaScript
|
ประวัติการแก้ไข 2016-10-11 17:00:59 2016-10-11 17:02:15
|
 |
 |
 |
 |
Date :
2016-10-11 16:59:56 |
By :
znorei |
View :
1084 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |