我試圖創建一個抽象根狀態並在其中激活子狀態之前解析其中的所有數據 - 通過使用ui-router從事異步數據加載(來自服務器)事先激活任何路線/國家等如何獲取ui-router stateHelper工作
爲此,我試圖使用ui-router.stateHelper - 如this answer建議。
我有ui-router
$stateProvider
正常工作之前在試圖stateHelper
:
我以前 app.js文件ui-router
代碼看起來是這樣的:
myApp.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('page1', {
url : '/page1',
templateUrl : 'templates/page1.html'
})
.state('page2', {
url : '/page2',
templateUrl : 'templates/page2.html'
})
});
我的index.html樣子:
<div>
<a ui-sref="page1"><img src="images/page1_button.jpg></a>
<a ui-sref="page2"><img src="images/page2_button.jpg></a>
</div>
<div id="template_contents" ui-view></div>
它工作正常沒有問題(除了狀態和控制器會加載之前主myApp.run完成 - 即使我的.run功能有承諾等)
由於'更新'stateHelper,我的app.js看起來像:
myApp.config(function($urlRouterProvider, stateHelperProvider) {
stateHelperProvider
.state({
name: 'root',
template: '<ui-view/>',
abstract: true,
resolve: {
// haven't got to this point yet :-/
},
children: [
{
name: 'page1',
url : '/page1',
templateUrl : 'templates/page1.html'
},
{
name: 'page2',
url : '/page2',
templateUrl : 'templates/page2.html'
},
]
});
});
現在的應用程序不改變狀態/加載模板,它給我下面的控制檯錯誤:
Error: Could not resolve 'page1' from state ''
什麼導致這個錯誤?
使用stateHelper
時,html和ui-sref
必須更新/更改嗎? (相當缺乏文檔中提到的沒有......缺乏信息指示HTML方應該是一樣的ui-router
格式)
只是嘗試沒有stateHelper – 2015-01-27 01:26:17