Angularjs tab Loading spinner while rendering

前端 未结 5 1999
别跟我提以往
别跟我提以往 2021-02-05 10:51

I have a page with some tabs and each tab has large amount of angularjs bindings.This is sample page where i am facing issue.Each tabs take about 10 seconds to render.

5条回答
  •  醉酒成梦
    2021-02-05 11:16

    You can make custom directive for each li example loading-counter , then add dependency service which will hold counter, and in each directive inside link function you can call

    var app = angular.module('app', []);
    
    app.controller('List', function(LoadingCounter) {
    
      this.tabs = [{
        title: "Test tab",
        url: "http://google.sk"
      }, {
        title: "Test tab",
        url: "http://google.sk"
      }, {
        title: "Test tab",
        url: "http://google.sk"
      }]
    
      this.LoadingCounter = LoadingCounter;
    
    });
    
    app.directive('spinningLoader', function(LoadingCounter) {
      return {
        restrict: 'A',
        scope: {
          max: "="
        },
        link: function(scope) {
          LoadingCounter.updateCounter(scope.max);
        }
      }
    });
    
    app.factory('LoadingCounter', function($timeout) {
      var service = {};
    
      service.currentCounter = 0;
      service.finished = false;
      service.updateCounter = function(max) {
        service.currentCounter++;
        if (service.currentCounter == max) {
          //example timeout
          $timeout(function() {
            service.finished = true;
          }, 2000);
    
        }
      }
      service.isFinished = function() {
        return service.finished;
    
      }
      return service;
    });
    .hidden {
      display: none;
    }
    
    
    
      
    Loading
    • {{tab.title}}

提交回复
热议问题