2014-01-24 45 views

回答

43

時,如果你看一下文檔的$state.get()的UI路由器的最新版本,你會發現,沒有傳遞參數,有一種方法可以列出所有登記狀態該函數應返回所有配置的狀態對象的數組。

/** 
* @ngdoc function 
* @name ui.router.state.$state#get 
* @methodOf ui.router.state.$state 
* 
* @description 
* Returns the state configuration object for any state by passing the name 
* as a string. Without any arguments it'll return a array of all configured 
* state objects. 
* 
* @param {string|object} stateOrName The name of the state for which you'd like 
* to get the original state configuration object for. 
* @returns {object} State configuration object or array of all objects. 
*/ 
+1

你如何做同樣的事情,但適當的嵌套? IE:我有5個州,但其中兩個州有3個州。但'$ state.get()'返回一個由11個項目組成的數組,而不是由5個項目組成的數組,其中兩個項目具有嵌套數組。 – Suamere

+0

@Suamere在這裏看看我的答案:http://stackoverflow.com/a/43658936/2367938 – Jacka