How to pass an object into a state using UI-router?

In version 0.2.13, You should be able to pass objects into $state.go, $state.go(‘myState’, {myParam: {some: ‘thing’}}) $stateProvider.state(‘myState’, { url: ‘/myState/{myParam:json}’, params: {myParam: null}, … and then access the parameter in your controller. $stateParams.myParam //should be {some: ‘thing’} myParam will not show up in the URL. Source: See the comment by christopherthielen https://github.com/angular-ui/ui-router/issues/983, reproduced here for … Read more

How to pass parameters using ui-sref in ui-router to the controller

I’ve created an example to show how to. Updated state definition would be: $stateProvider .state(‘home’, { url: ‘/:foo?bar’, views: { ”: { templateUrl: ‘tpl.home.html’, controller: ‘MainRootCtrl’ }, … } And this would be the controller: .controller(‘MainRootCtrl’, function($scope, $state, $stateParams) { //.. var foo = $stateParams.foo; //getting fooVal var bar = $stateParams.bar; //getting barVal //.. $scope.state … Read more

Redirect a state to default substate with UI-Router in AngularJS

Update: 1.0 Onwards Supports redirectTo out of the box. https://ui-router.github.io/ng1/docs/latest/interfaces/state.statedeclaration.html#redirectto I created an example here. This solution comes from a nice “Comment” to an an issue with redirection using .when() (https://stackoverflow.com/a/27131114/1679310) and really cool solution for it (by Chris T, but the original post was by yahyaKacem) https://github.com/angular-ui/ui-router/issues/1584#issuecomment-75137373 So firstly let’s extend main with redirection … Read more

How to reload the current state?

I found this to be the shortest working way to refresh with ui-router: $state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams Update for newer versions: $state.reload(); Which is an alias for: $state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: true }); Documentation: https://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state#methods_reload

AngularJS – UI-router – How to configure dynamic views

There is a plunker showing how we can configure the views dynamically. The updated version of the .run() would be like this: app.run([‘$q’, ‘$rootScope’, ‘$state’, ‘$http’, function ($q, $rootScope, $state, $http) { $http.get(“myJson.json”) .success(function(data) { angular.forEach(data, function (value, key) { var state = { “url”: value.url, “parent” : value.parent, “abstract”: value.abstract, “views”: {} }; // … Read more

What is the difference between angular-route and angular-ui-router?

ui-router is a 3rd-party module and is very powerful. It supports everything the normal ngRoute can do as well as many extra functions. Here are some common reason ui-router is chosen over ngRoute: ui-router allows for nested views and multiple named views. This is very useful with larger app where you may have pages that … Read more