当用户点击按钮时。我想知道如何获取内容,渲染它,然后更改视图并进行转换是可行的。
例如,在使用角度档案开发的this website中。
在呈现视图时,如何使用转换显示信息? plunkr或服务器中的任何一个例子?
答案 0 :(得分:1)
使用默认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;
}
};
});