javascript - put a spinner while $http.get fetches data from RESTful API in agular js -


i fetching data function in controller:

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

it working fine , fast enough. if there lots of items fetch?! want put spinner while data being fetched.

how can this?

in controller,

var fetchstoreitems = function () {     $scope.loading = true;            //define `$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 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 loading image according `$scope.loading` 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -