【发布时间】:2016-02-10 10:01:12
【问题描述】:
当用户点击按钮时。我想知道如何获取内容、渲染它,然后更改视图并进行转换。
例如,在this website 开发的带有角度存档的效果。
如何在渲染视图时使用转换来显示信息? plunkr 或某种服务器中的任何示例?
【问题讨论】:
标签: javascript angularjs transitions
当用户点击按钮时。我想知道如何获取内容、渲染它,然后更改视图并进行转换。
例如,在this website 开发的带有角度存档的效果。
如何在渲染视图时使用转换来显示信息? plunkr 或某种服务器中的任何示例?
【问题讨论】:
标签: javascript angularjs transitions
使用默认的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;
}
};
});
【讨论】: