如何控制 angular 中的转换以避免看到内容加载

How to control transitions in angular to avoid seeing content loading

当用户点击按钮时。我想知道如何获取内容、渲染内容,然后更改视图并进行过渡。

例如,在 this website 开发中使用 angular 存档效果。

如何在呈现视图时使用转换显示信息? plunkr 或某种服务器中的任何示例?

使用默认值 ng-route,您可以定义 resolve 属性。在更改位置之前,必须解析(从服务器检索)这些属性的值。这将防止在初始化之前显示任何视图。

查看此 plunker 示例。

重度观看建议

Angular 没有任何内置机制可以在 DOM 完成渲染时发出通知。但是,您可以将某些代码排队,以便在摘要周期完成时执行。

// Execute a function at the end of the current digest queue.

$timeout(function() {
  // Do your thing here
  $rootScope.displayView = true;
}, 0);

另一种方法是让所有 ng-repeats 在最后一个条目添加到 DOM 时通知您。请注意,如果您在视图中有多个 ng-repeats,您将需要某种机制来跟踪它们(承诺是您的朋友)。

app.directive('postRepeat', function() {
  return function(scope, element, attrs) {
    // The ng-repeat directive sets the $last property on the scope to
    // true when processing the last item.
    if (scope.$last){
      $rootScope.displayView = true;
    }
  };
});