我正在尝试阻止页面先于数据加载的情况,以便您在页面加载时更新 View 。
在 UI-router 中,您可以设置一个“解析”,它可以在加载页面之前运行一个方法并检索数据,这非常有效,但我似乎只能对一种方法执行此操作。有没有办法在加载页面之前在一个解析中运行多个方法?
最佳答案
实际上 resolve
也可以接收一个对象。并且每个属性都必须在 Controller 之前解析,然后才能实现状态。
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).
例如:
$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');
}
}
}
关于javascript - 如何设置多个 Angular UI-router 解析语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40241641/