AngularJs: Loop through / return all states in $ stateProvider / ui-router

This is a dumb question, but should I return all instances of $stateProvider.state in my app.js (my AngularJS configuration file), how would I do it? For example, when I used ngRoute , I could do something like this in my .run() block:

 .run(function ($route) { var someArray = []; angular.forEach($route.routes, function (route, path) { if (route.someKey) { console.log(path); // do something with route.someKey!!! someArray.push(route.someKey); } }); }); 

However, in my application, I use ui-router , and I can not do something like this with $state ? I am reading about it now, but if anyone has a quick answer, let me know!

+4
source share
1 answer

Found! $state.get() works! I must have missed this earlier in the docs!

$state.get() displays an array of objects, I run console.log($state.get); and I get:

 [ { "name": "", "url": "^", "views": null, "abstract": true }, { "abstract": true, "template": "<ui-view/>", "name": "app" }, { "url": "/login", "templateUrl": "login/views/login.html", "controller": "LoginCtrl", "publicAccess": true, "name": "app.login" }, { "abstract": true, "url": "/home", "templateUrl": "home/views/home-wrapper.html", "controller": "HomeCtrl", "name": "app.loggedInHome" } ] 
+8
source

All Articles