1

コントローラーでこの関数を使用してデータを取得しています:

var fetchStoreItems = function () {
    return $http.get('/enterprises/_store').then(function (response) {
        $scope.items = response.data;
    }, function (errResponse) {
        console.error("Error while fetching data")
    })
};

それはうまく機能し、十分に高速です。しかし、フェッチするアイテムがたくさんある場合はどうなりますか?! データの取得中にスピナーを置きたい。

これどうやってするの?

4

2 に答える 2

3

コントローラーで、

var fetchStoreItems = function () {
    $scope.loading = true;            //define a `$scope` variable; show loading image when ajax starts
    return $http.get('/enterprises/_store').then(function (response) {
        $scope.items = response.data;
        $scope.loading = false;       //hide loading image  when ajax successfully completes
    }, function (errResponse) {
        console.error("Error while fetching data");
        $scope.loading = false;      //hide loading image  when ajax error
    })
};

<img src="pathToLoadingImage" ng-show="loading" />  // show the loading image according to `$scope.loading`
于 2014-12-02T07:19:35.617 に答える
1

残りの API 呼び出しの一部に使用したい場合は、kalhano の回答がうまく機能します。ただし、すべての angular http 呼び出しにスピナーが必要な場合は、インターセプターの使用を検討してください。

それについては、このリンクを確認してください: インターセプターが説明された Http call docs

于 2014-12-02T07:41:08.023 に答える