當用戶單擊表單上的按鈕時,我希望它禁用所有控件,然後轉到服務器以執行操作,因此它們不能在更改結果之前更改任何值背部。當結果返回時,表單可以重新啓用。角色綁定在阻止調用之前不會觸發
然而,這是我的代碼
$scope.restartNode = function() {
$scope.isBusy = true;
$scope.disableControls = true;
SEApplicationService.restartNode();
$scope.isBusy = false;
$scope.disableControls = false;
}
的restartNode是阻塞調用到Web API方法,但是管制沒有得到禁止。如果我註釋掉最後一行 - 將控件重新設置爲啓用,我可以看到所有表單控件都按預期變灰。這裏發生了什麼?
我的阻塞調用是
appService.restartNode = function() {
return $http.post("/SEFlex/SEFlexAdmin/RestartNode", {
isPrimary: appService.primarySelected
}).success(function (response, status, headers, config) {
appService.refreshData();
}).error(function (reason, status, headers, config) {
console.log(reason);
});
}
編輯:添加refreshData()函數
appService.refreshData = function() {
return $http.post("/SEFlex/SEFlexAdmin/GetNodesStatus")
.success(function (response, status, headers, config) {
if (response) {
angular.forEach(response.data, function(value) {
if (value.isPrimary) {
appService.ServiceStatus.PrimaryStatus = value.status;
appService.ServiceStatus.PrimaryPools = value.poolCount;
appService.ServiceStatus.PrimaryContainers = value.containerCount;
appService.ServiceStatus.PrimaryNodes = value.nodeCount;
} else {
appService.ServiceStatus.SecondaryStatus = value.status;
appService.ServiceStatus.SecondaryPools = value.poolCount;
appService.ServiceStatus.SecondaryContainers = value.containerCount;
appService.ServiceStatus.SecondaryNodes = value.nodeCount;
}
});
}
})
.error(function (reason, status, headers, config) {
console.log(reason);
});
}
謝謝,then()方法會在異步調用的success()部分之前還是之後運行?即將appService.refreshData()運行並在then()承諾被調用之前完全完成? – NZJames
是'appService.refreshData();'也是異步的?如果是這樣,它會返回'$ http'?可以鏈接的承諾,如果是這樣,但需要使用'然後'而不是'成功' – charlietfl
剛編輯的帖子顯示refreshData()函數 – NZJames