I am trying to stop a situation where the page loads prior to the data, so you get the view updating whilst page is loading.
我试图阻止页面在数据之前加载的情况,因此您在页面加载时获得视图更新。
In UI-router, you can set a 'resolve' which can run a method and retrieve data prior to loading page, which is working fantastically, but I seem to only be able to do this for one method. Is there a way to run multiple methods in a resolve prior to loading the page?
在UI路由器中,您可以设置一个'resolve',它可以运行一个方法并在加载页面之前检索数据,这很有效,但我似乎只能为一个方法执行此操作。有没有办法在加载页面之前在解析中运行多个方法?
1 个解决方案
#1
2
Actually resolve
can receive an object as well. And each property would have to be resolved before the controller, so then the state could be achieved.
实际上,resolve也可以接收一个对象。并且每个属性都必须在控制器之前解析,因此可以实现状态。
Each of the objects in resolve below must be resolved (via
deferred.resolve()
if they are apromise
) before thecontroller
is instantiated. Notice how each resolve object is injected as a parameter into the controller (UI-Router docs for resolve).在实例化控制器之前,必须解析下面解决的每个对象(通过deferred.resolve(),如果它们是一个promise)。请注意每个解析对象如何作为参数注入控制器(用于解析的UI-Router文档)。
For example:
$stateProvider.state('myState', {
resolve: {
resolve0: function () { // resolve with plain value
return 'somedata';
},
resolve1: function ($q) { // resolve with promise
return $q.resolve('somedata');
},
resolve2: function ($q) { // reject with promise, it will preven state to finish change
return $q.reject('some error');
}
}
}
#1
2
Actually resolve
can receive an object as well. And each property would have to be resolved before the controller, so then the state could be achieved.
实际上,resolve也可以接收一个对象。并且每个属性都必须在控制器之前解析,因此可以实现状态。
Each of the objects in resolve below must be resolved (via
deferred.resolve()
if they are apromise
) before thecontroller
is instantiated. Notice how each resolve object is injected as a parameter into the controller (UI-Router docs for resolve).在实例化控制器之前,必须解析下面解决的每个对象(通过deferred.resolve(),如果它们是一个promise)。请注意每个解析对象如何作为参数注入控制器(用于解析的UI-Router文档)。
For example:
$stateProvider.state('myState', {
resolve: {
resolve0: function () { // resolve with plain value
return 'somedata';
},
resolve1: function ($q) { // resolve with promise
return $q.resolve('somedata');
},
resolve2: function ($q) { // reject with promise, it will preven state to finish change
return $q.reject('some error');
}
}
}