Angular-ui-router: ui-sref-active and nested states

Instead of this- <li ui-sref-active=”active”> <a ui-sref=”posts.details”>Posts</a> </li> You can do this- <li ng-class=”{active: $state.includes(‘posts’)}”> <a ui-sref=”posts.details”>Posts</a> </li> Currently it doesn’t work. There is a discussion going on here (https://github.com/angular-ui/ui-router/pull/927) And, it will be added soon. UPDATE: For this to work, $state should be available in view. angular.module(‘xyz’).controller(‘AbcController’, [‘$scope’, ‘$state’, function($scope, $state) { $scope.$state = … Read more

Difference between $state.transitionTo() and $state.go() in Angular ui-router

Are you referring to the AngularUI Router? If so, the wiki specifies the differences: $state.go(to [, toParams] [, options]) Returns a Promise representing the state of the transition. Convenience method for transitioning to a new state. $state.go calls $state.transitionTo internally but automatically sets options to { location: true, inherit: true, relative: $state.$current, notify: true }. … Read more

Angular ui router – Redirection doesn’t work at all

What we would need here, is to do NOT redirect, if the state TO is already the ‘login’. Just a drafted adjustment would be $rootScope.$on( ‘$stateChangeStart’, function(e, toState , toParams , fromState, fromParams) { var isLogin = toState.name === “login”; if(isLogin){ return; // no need to redirect anymore } … And also, we should call … Read more

ui-router dynamic template path

You might be looking for dynamic template name based on the state params $stateProvider.state(‘contacts’, { templateUrl: function ($stateParams){ return ‘/partials/contacts.’ + $stateParams.filterBy + ‘.html’; } }) See the docs for more information https://github.com/angular-ui/ui-router/wiki#templates

How to achieve that “ui-sref” be conditionally executed?

This answer inspired me to create a directive that allows me to interrupt the chain of events that end up changing state. For convenience and other uses also prevents the execution of ng-click on the same element. javascript module.directive(‘eatClickIf’, [‘$parse’, ‘$rootScope’, function($parse, $rootScope) { return { // this ensure eatClickIf be compiled before ngClick priority: … Read more