2016-09-20 62 views
0

在頁面內容加載幾秒鐘後加載我的頁眉。之後將內容壓下。 我想要首先加載標題。使用ng-include時導航欄加載頁面內容

下面是HTML

<body ng-app="tiide" ng-cloak> 

    <div ng-controller="headerController"> 
     <div ng-include src=header.url></div> 
     <script type="text/ng-template" id="header.html"></script> 
    </div> 

    <div> 
     Hello.This is the main content of the page. 
    </div> 
</body> 

這是我主要的JavaScript文件

var app = angular.module('tiide',['ngMaterial','ngAnimate','ngMessages','ngAria']); 

app.controller('headerController', ['$scope', function($scope){ 
    $scope.header = {name: "header.html", url: "partials/header.html"}; 
}]); 

這裏與角材料製成的頭

<md-toolbar class="toolbar"> 
     <div class="md-toolbar-tools"> 
     <md-button aria-label="Go Back"> 
      Go Back 
     </md-button> 
     <h2> 
      <span>This is the toolbar.</span> 
     </h2> 
     <span flex></span> 
     <md-button class="md-raised" aria-label="Learn More"> 
      Learn More 
     </md-button> 
     </div> 
    </md-toolbar> 
+0

你試過用的setTimeout()功能... – learner

+0

@learner它做什麼。它是否減緩了頁面加載之前的時間或什麼? – joomo

+0

是的,你可以設置幾秒鐘後載入某個特定位置的時間 – learner

回答

0

速戰速決這是使用$超時()和(默認爲0)沒有指定時間,這將在線程結束應用更改:

app.controller('headerController', ['$scope', '$timeout', function($scope, $timeout){ 
    $timeout(function(){ 
     $scope.header = {name: "header.html", url: "partials/header.html"}; 
    }); 
}]);