我試圖讓toState
對象url
在$stateChangeStart
事件的狀態basic.tasks
:toState.url值不是嵌套狀態
$rootScope.$on("$stateChangeStart", function (event, toState, toParams, fromState, fromParams) {
...
console.log(toState.name); // > basic.tasks
console.log(toState.url); // > /tasks
...
}
國家配置:
$stateProviderRef
.state('basic',{
url: '/b',
template: require('source/basic/templates/basic.html'),
controller: 'BasicController',
abstract: true
})
.state('basic.tasks', {
url: '/tasks',
template: require('source/basic/templates/tasks/tasks.html'),
controller: 'TasksController',
})
toState.url的值是/tasks
而不是/b/tasks
。有沒有辦法獲得包括父狀態在內的完整散列。
我嘗試使用$window.location.hash
,但它只給出fromState
的完整散列路徑,因爲它在狀態更改完成之前不會更新。
您可以將引號添加到'BasicController'並重試嗎?可能是第一個狀態是由JS正確解釋的 – Zakaria
不好意思,這不是問題。我只是在這個問題中錯過了控制器名稱的引用。我會編輯它。 –