javascript - Unable to show spinning icon when button is clicked -


the below code gets data end , displays on browser on page load. when user clicks on reload data button , again has data backend , display on browser. issue when user clicks on reload data button, need show spinning icon , once data loaded replaced data. below code spinning icon showing somewhere down page, still occupying space of $scope.html old data showing blank , after blank space displaying spinner.how can show spinner user hits reload data button?

<table style="width:100%;height:80%;" ng-controller="loadingsamplectrl"> <tr> <td><button type="button" ng-click="loaddata()">reload data</button></td></tr> <tr ng-show="loading"> <td colspan="5" style="white-space: nowrap;text-align: center; font-size:36px;"><div class="loader"><i class="fa fa-spinner fa-spin" ></i> loading<span class="loader__dot">.</span><span class="loader__dot">.</span><span class="loader__dot">.</span></div></td></tr>          <object-reloadable></object-reloadable>  </table> 

js code:

app.directive('objectreloadable', function() { var link = function(scope, element, attrs) { var currentelement = element;  scope.$watch('pdfname', function(newvalue, oldvalue) {  if (newvalue !== oldvalue) {      scope.loading = false;      scope.pdfname = newvalue;       if(scope.pdfname.filepath == "undefined" ||  scope.pdfname.filepath==null){ scope.loading=true; } else { alert("in else"); scope.html = '<object style="width: 100%; height: 1200px;overflow-y: hidden; cursor:pointer;" type="application/pdf" data="' + scope.pdfname.filepath + '" ></object>'; /* scope.pdfname = newvalue;*/ scope.loading=false;  }var replacementelement = angular.element(scope.html);     currentelement.replacewith(replacementelement);     currentelement = replacementelement; } }); }; return { restrict: 'e', scope: false, link: link }; })  myapp.controller('loadingsamplectrl', function ($scope, filesservice) { $scope.loaddata = function () { $scope.loading = true; $scope.html=''; filesservice.fileread().then( function (response) {      $scope.filepathandname = response;        if(window.navigator.mssaveoropenblob){     $scope.iebrowser = true;     $timeout(function() {         $scope.pdfname = response;        }, 0);     } else {     $scope.iebrowser = false;     $scope.filepathandname = response;      $scope.loading = false;      } }, function (errresponse) {     $rootscope.showerror("internal error" + errresponse); });  } $scope.loaddata(); }); //service call _myfileservicefactory.fileread= function(){ var deferred = $q.defer(); var repurl = appurl+'/myfilesdata/generatedefectssummarypdf.form'; $http.get(repurl).then(     function (response) {         deferred.resolve(response.data);     },     function(errresponse){         console.error('error ' + errresponse);         deferred.reject(errresponse);     } ); return deferred.promise; } 

ps: have assigned scope.html='' wherever required still when user clicks on reload button still showing blank space , down somewhere showing spinning icon.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -