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.
$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.
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.
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.
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).
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"
}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With