Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Angularjs UI Router list of states?

Is there any way to get the list of states configured for the application through Angularjs UI Router? i.e After configuring all the states (aka routes in angular), how to get the array of these states or state objects.

In other words, what is the equivalent of Angular's built in router's "$route.routes" in Angular UI Router?

Tried to find in UI Router's api documentation, but can't find it.

like image 909
Nexus23 Avatar asked Oct 20 '14 11:10

Nexus23


People also ask

What is $state in AngularJS?

$stateProvider is used to define different states of one route. You can give the state a name, different controller, different view without having to use a direct href to a route. There are different methods that use the concept of $stateprovider in AngularJS.

What is ui Router in AngularJS?

Angular-UI-Router is an AngularJS module used to create routes for AngularJS applications. Routes are an important part of Single-Page-Applications (SPAs) as well as regular applications and Angular-UI-Router provides easy creation and usage of routes in AngularJS.

What is ui sref in AngularJS?

State-To-State Navigation of ui-sref in Angular The ui-sref directive is the first option to navigate from one state to another. The href property of the HTML anchor element is likely acquainted with you; likewise, the ui-sref directive refers to a state reference.

What is ui in Router?

UI-Router is the defacto standard for routing in AngularJS. Influenced by the core angular router $route and the Ember Router, UI-Router has become the standard choice for routing non-trivial apps in AngularJS (1. x).


1 Answers

Use $state.get().

Following in your controller

app.controller('MainCtrl', function ($state) {
  console.log(angular.toJson($state.get()));
});

Would spit out something like

[{  
  "name":"",
  "url":"^",
  "views":null,
  "abstract":true
 },{  
  "name":"main",
  "url":"/main",
  "controller":"MainCtrl",
  "templateUrl":"main.html"
}]
like image 113
Mikko Viitala Avatar answered Sep 30 '22 16:09

Mikko Viitala