Angularjs - Hide content until DOM loaded

后端 未结 6 2190
深忆病人
深忆病人 2020-12-01 02:17

I am having an issue in Angularjs where there is a flicker in my HTML before my data comes back from the server.

Here is a video demonstrating the issue: http://you

6条回答
  •  佛祖请我去吃肉
    2020-12-01 03:21

    Since you asked for a directive, try this.

    .directive('showOnLoad', function() {
      return {
        restrict: 'A',
        link: function($scope,elem,attrs) {
    
          elem.hide();
    
          $scope.$on('show', function() {
            elem.show();
          });
    
        }
      }
    });
    

    Stick (show-on-load) in your element, and in your controller inject $rootScope, and use this broadcast event when the html has loaded.

    $rootScope.$broadcast('show');
    

提交回复
热议问题