Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在$http.get从angularjs中的RESTful API获取数据时放置微调器_Javascript_Angularjs_Angularjs Http - Fatal编程技术网

Javascript 在$http.get从angularjs中的RESTful API获取数据时放置微调器

Javascript 在$http.get从angularjs中的RESTful API获取数据时放置微调器,javascript,angularjs,angularjs-http,Javascript,Angularjs,Angularjs Http,我正在控制器中使用此函数获取数据: var fetchStoreItems = function () { return $http.get('/enterprises/_store').then(function (response) { $scope.items = response.data; }, function (errResponse) { console.error("Error while fetching data")

我正在控制器中使用此函数获取数据:

var fetchStoreItems = function () {
    return $http.get('/enterprises/_store').then(function (response) {
        $scope.items = response.data;
    }, function (errResponse) {
        console.error("Error while fetching data")
    })
};
它运行良好,速度足够快。但是如果有很多东西要拿怎么办?!我想在提取数据时放置一个微调器

我如何才能做到这一点?

在您的控制器中

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`
var fetchStoreItems=函数(){
$scope.load=true;//定义一个`$scope`变量;在ajax启动时显示加载图像
返回$http.get('/enterprises/_store')。然后(函数(响应){
$scope.items=response.data;
$scope.load=false;//在ajax成功完成时隐藏加载图像
},函数(错误响应){
console.error(“获取数据时出错”);
$scope.loading=false;//在ajax错误时隐藏加载图像
})
};
//根据“$scope.loading”显示加载图像`
在控制器中

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`
var fetchStoreItems=函数(){
$scope.load=true;//定义一个`$scope`变量;在ajax启动时显示加载图像
返回$http.get('/enterprises/_store')。然后(函数(响应){
$scope.items=response.data;
$scope.load=false;//在ajax成功完成时隐藏加载图像
},函数(错误响应){
console.error(“获取数据时出错”);
$scope.loading=false;//在ajax错误时隐藏加载图像
})
};
//根据“$scope.loading”显示加载图像`

如果您想将其用于某些rest API调用,kalhano的答案很有效。 但是,如果您想使用所有的角HTTP调用,则可以考虑使用拦截器。

请检查此链接以了解:

如果您想将其用于某些rest API调用,kalhano的答案很有效。 但是,如果您想使用所有的角HTTP调用,则可以考虑使用拦截器。

请检查此链接以了解: