Directing the user to a child state when they are transitioning to its parent state using UI-Router

First, add a property to the ‘manager.staffDetail.view’ state of abstract:true. This isn’t required, but you want to set this since you’d never go to this state directly, you’d always go to one of it’s child states. Then do one of the following: Give the ‘manager.staffDetail.view.schedule’ state an empty URL. This will make it match the … Read more

Injecting $state (ui-router) into $http interceptor causes circular dependency

The Fix Use the $injector service to get a reference to the $state service. var interceptor = [‘$location’, ‘$q’, ‘$injector’, function($location, $q, $injector) { function success(response) { return response; } function error(response) { if(response.status === 401) { $injector.get(‘$state’).transitionTo(‘public.login’); return $q.reject(response); } else { return $q.reject(response); } } return function(promise) { return promise.then(success, error); } }]; … Read more

How can I fix ‘Maximum call stack size exceeded’ AngularJS

I’ve created an example, playing with default pages and auth/unauth user. Similar issue could be seen here Firstly this would be the listener: app.run(function ($rootScope, $state, $location, Auth) { $rootScope.$on(‘$stateChangeStart’, function (event, toState, toParams, fromState) { var shouldLogin = toState.data !== undefined && toState.data.requireLogin && !Auth.isLoggedIn ; // NOT authenticated – wants any private stuff … Read more

How to delete ‘#’ sign in angular-ui-router URLs

You need to enable HTML5Mode if you want navigation without hash tags: app.config([“$locationProvider”, function($locationProvider) { $locationProvider.html5Mode(true); }]); You will also need to tell angular the root URL of your app by adding the following code to the <head> of your HTML file: <base href=”https://stackoverflow.com/”> Be aware that support for HTML5 mode depends on the browser. … Read more

Angular UI-Router $urlRouterProvider .when not working *anymore*

EDIT: version 0.2.13 – breaking change The original post was working with the UI-Router 0.2.12-. A fix in 0.2.13 disables this solution. Please follow the workaround here: Angular UI-Router $urlRouterProvider .when not working when I click <a ui-sref=”…”> ORIGINAL: There is one issue, I found, causing similar issue. There is a working example with full … Read more

Angular/UI-Router – How Can I Update The URL Without Refreshing Everything?

The code snippets you’ve used are a bit far from the correct ui-router settings. I would suggest to you, check this demo application: http://angular-ui.github.io/ui-router/sample/#/contacts/1. Here we can see how the List is “fixed” while Detail is changed without any page refresh. The code of this example download here https://github.com/angular-ui/ui-router/tree/master/sample. What should help a lot to … Read more

Angular UI Router: decide child state template on the basis of parent resolved object

There is a working example. Instead of templateUrl we should use the templateProvider. This is new state def: $stateProvider .state(‘parentstate.childs’, { url: ‘/edit’, views: { “view1@parentstate”: { templateUrl: ‘views.view1.html’, controller: ‘view1Ctrl’, }, “view2@parentstate”: { templateProvider: function($http, $stateParams, OBJ) { var obj = OBJ.get($stateParams.objId); var templateName = obj.id == 1 ? “views.view2.html” : “views.view2.second.html” ; return … Read more

How would I have ui-router go to an external link, such as google.com?

Angular-ui-router doesn’t support external URL, you need redirect the user using either $location.url() or $window.open() I would suggest you to use $window.open(‘http://www.google.com’, ‘_self’) which will open URL on the same page. Update You can also customize ui-router by adding parameter external, it can be true/false. $stateProvider .state(‘external’, { url: ‘http://www.google.com’, external: true }) Then configure … Read more