Ionic Modal仅显示一次

Ionic Modal displays only once

本文关键字:一次 Modal 显示 Ionic      更新时间:2023-09-26

从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);
}

感谢@grundy我已经修改了进行API调用的函数中的两行,现在它可以工作了:1-在重新分配http调用之前清空promise。2-从http调用中删除缓存:

var promiseDaily = $http({method: 'GET', url: urlDaily, cache: false});

重要的是CCD_ 1不正确。即使控制台中没有因此而记录错误,它也不起作用。