Da verwende ich AJAX-Anfrage mit $ http. Es dauert lange, da meine Operation auf dem Server Zeit braucht. Ich muss den Loader während der Verarbeitung anzeigen, aber der Loader wird nicht angezeigt. Obwohl mein Code korrekt zu sein scheint. Ich habe verschiedene Methoden ausprobiert, aber nicht funktioniert.Ladeprogramm wird nicht auf AJAX-Anfrage in angular angezeigt js
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);
});
}
Sin ce Ich werde isLoading als "true" beim Start aktivieren und dann, wenn die Anfrage abgeschlossen ist, mache ich isLoading "false". Wo ist das Problem im Code?
Sie setzen es auf dem '$ rootScope', so müssen Sie tun:' ng-show = "$ root.isLoading" ' – devqon
Aber das auch nicht funktioniert. Da rootscope auf alles innerhalb der App zugreifen kann – Umar