由於我使用$ http使用ajax請求。從我在服務器上的操作需要很長時間,我需要在處理請求時顯示加載器,但加載器不顯示。雖然我的代碼似乎正確。我嘗試了不同的方法,但沒有奏效。加載程序未在角度js上的ajax請求中顯示
的index.html
<body ng-app="app">
<!-- loader, can be used on multiple pages-->
<div class="loading loader-quart" ng-show="isLoading"></div>
<!-- my logic -->
</body>
addCtrl.js
//method to get all the attributes and send to server using service
$scope.add = function() {
if ($scope.Option == 'newInstance')
$scope.singleObject.FK_Name = 'MetisEmptyTemplate';
$rootScope.isLoading = true;
var featuresList = websiteService.getUpdatedTree($scope.treeDataSource);
var formData = new Website("", $scope.singleObject.Name, $scope.singleObject.DisplayName, $scope.singleObject.Description, $scope.singleObject.State, "", $scope.singleObject.FK_Name, $scope.singleObject.Email, featuresList);
websiteService.addwebsite(formData);
$rootScope.isLoading = false;
}
websiteService.js
//service to add website
this.addwebsite = function (website) {
$http({
method: 'POST',
url: $rootScope.url + 'Add',
data: JSON.stringify(website),
contentType: 'application/json'
}).success(function (data) {
alert(data);
}).error(function (data, status, headers, config) {
//alert(data);
});
}
仙我打算在開始時將isLoading改爲「true」,然後在請求完成後我將加載「false」。代碼中的問題在哪裏?
你把它放在了'$ rootScope',所以你需要做的:'NG秀= 「$ root.isLoading」' – devqon
但是,這也不起作用。由於根目錄可以訪問應用程序內的所有內容 – Umar