angularjs 模型准备好后如何加载视图
how to load view after model is ready in angularjs
我想加载我的视图,即仅在我的模式完全准备好后生成 DOM。我如何在不使用 $timeout 的情况下在 AngularJs 中执行此操作。现在,每当我启动页面时,都会显示空白页面,然后慢慢地填充我的数据。关于我该怎么做的任何想法都会很棒。
在加载内容之前,您需要使用 resolve 加载数据。它会让您的视图一直等到您的数据准备就绪。
这是我使用 ui-router
的代码之一
.state('statename',
{
url : "addressbarurl",
templateUrl: 'templateurl',
controller:'samplecontroller',
resolve : {sampledetails : function(){
return "asdf";
}
}
})
控制器
app.controller('samplecontroller',['sampledetails',function(sampledetails){
console.log(sampledetails); //will output asdf
//your code here
}]);
我想加载我的视图,即仅在我的模式完全准备好后生成 DOM。我如何在不使用 $timeout 的情况下在 AngularJs 中执行此操作。现在,每当我启动页面时,都会显示空白页面,然后慢慢地填充我的数据。关于我该怎么做的任何想法都会很棒。
在加载内容之前,您需要使用 resolve 加载数据。它会让您的视图一直等到您的数据准备就绪。
这是我使用 ui-router
的代码之一 .state('statename',
{
url : "addressbarurl",
templateUrl: 'templateurl',
controller:'samplecontroller',
resolve : {sampledetails : function(){
return "asdf";
}
}
})
控制器
app.controller('samplecontroller',['sampledetails',function(sampledetails){
console.log(sampledetails); //will output asdf
//your code here
}]);