Angular 在加载其他视图之前不显示视图

Angular dont show view before other view is loaded

本文关键字:视图 显示 Angular 加载 其他      更新时间:2023-09-26

我有三个观点:导航、主要内容、页脚。

我使用 ui-router,当页面加载时,导航和页脚会立即加载,但在主要内容中,我请求获取一些数据,并且视图在导航和页脚后延迟了一秒钟,所以我坚持将空的中间内容保留到一秒钟。我怎样才能同时显示所有视图?

<div ng-include="'client/template/nav.tpl.html'"></div>
   <div class='main-wrapper'>
    <div ui-view='' class='view'></div>
   </div>
<div ng-include="'client/template/footer.tpl.html'"></div>

主要内容控制者:

function HomeController( $scope, promos ) {
    $scope.products = products.data; // this is come from the server directly, not ajax
  }

需要注意的一件事是,请求主内容的数据不是来自 ajax 请求,而是来自服务器请求及其全局请求。

在模板上使用 ng-cloak:

<div ng-cloak>
  <div ng-include="'client/template/nav.tpl.html'"></div>
   <div class='main-wrapper'>
     <div ui-view='' class='view'></div>
   </div>
  <div ng-include="'client/template/footer.tpl.html'"></div>
</div>