我正在从API调用中获取数据时显示一个简单的模态。当我触发加载一次时,模态显示并且数据将被加载但是第二次点击加载按钮时,模态不再加载。
$ionicModal.fromTemplateUrl('views/loading.html', {
scope: $scope,
backdropClickToClose: false,
hardwareBackButtonClose: true,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show();
alertServices.getInvoices()
.then(function(data) {
$scope.closeModal();
})
}
$scope.closeModal = function() {
$scope.modal.hide();
};
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
这是重启按钮,触发要显示的模态:
<ion-nav-buttons side="right">
<button class="button button-icon ion-android-refresh" ng-click="openModal()">
</button>
</ion-nav-buttons>
这是API调用的函数:
function getInvoices() {
var urlDaily = sharedProperties.Api +
"/salesinvoice/SalesInvoices?" +
"$select=OrderNumber,InvoiceToName,AmountDC&"
var urlWeekly = sharedProperties.Api +
"/salesinvoice/SalesInvoices?" +
"$select=OrderNumber,InvoiceToName,AmountDC&";
var promiseDaily = $http({method: 'GET', url: urlDaily, cache: 'true'});
var promiseWeekly = $http({method: 'GET', url: urlWeekly, cache: 'true'});
var promises = $q.all([promiseDaily, promiseWeekly, promiseMonthly]).then(function(data){
setData(data[0].data, 'SalesInvoice', 'Daily');
setData(data[1].data, 'SalesInvoice', 'Weekly');
});
return promises;
}
function setData(data, alert, type){
var invoicesList = data.d.results;
$localstorage.setObject('Setting' + alert + type, invoicesList);
}
答案 0 :(得分:0)
感谢@grundy 我在函数中更改了两行来进行API调用,现在它可以工作: 1-在重新分配http调用之前清空promises。 2-从http调用中删除缓存:
var promiseDaily = $http({method: 'GET', url: urlDaily, cache: false});
重要的是cache: 'false'
是正确的。即使由于它没有在控制台中记录错误,它也无法正常工作。