What is the Angular ui-router lifecycle? (for debugging silent errors)

After some experimenting, I figured out how to see into the lifecycle well enough to debug my app and get a feel for what was happening. Using all the events, including onEnter, onExit, stateChangeSuccess, viewContentLoaded from here, gave me a decent picture of when things are happening in a way that’s more both more flexible … Read more

How to extract query parameters with ui-router for AngularJS?

See the query parameters section of the URL routing documentation. You can also specify parameters as query parameters, following a ‘?’: url: “/contacts?myParam” // will match to url of “/contacts?myParam=value” For this example, if the url is /contacts?myParam=value then the value of $state.params will be: { myParam: ‘value’ }

Dynamically add meta description based on route in Angular

First create a SEOService or Something like below: import {Injectable} from ‘@angular/core’; import { Meta, Title } from ‘@angular/platform-browser’; @Injectable({ provideIn: ‘root’ // Add this to ensure your SEO service will be app-wide available }) export class SEOService { constructor(private title: Title, private meta: Meta) { } updateTitle(title: string) { this.title.setTitle(title); } updateOgUrl(url: string) { … Read more

How do I share $scope data between states in angularjs ui-router?

I created working plunker, showing how to use $scope and UI-Router. The state definition is unchanged: $stateProvider // States .state(“main”, { controller:’mainController’, url:”/main”, templateUrl: “main_init.html” }) .state(“main.1″, { controller:’mainController’, parent: ‘main’, url:”/1”, templateUrl: ‘form_1.html’ }) .state(“main.2”, { controller:’mainController’, parent: ‘main’, url: “/2”, templateUrl: ‘form_2.html’ }) But each state can have different controller. Why? because each … Read more

Why give an “abstract: true” state a url?

The reason you would use an abstract state is to keep your definition dry when you have a part of your url non-navigable. For example, say that you had a url scheme like the following: /home/index /home/contact However, for whatever reason in your design, this url was invalid (i.e. no purpose for a page): /home … Read more

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

(Angular-ui-router) Show loading animation during resolve process

EDIT: Here is an even easier solution, tested and working nicely: In my main controller I simply have $scope.$on(‘$stateChangeStart’, function(event, toState, toParams, fromState, fromParams) { if (toState.resolve) { $scope.showSpinner(); } }); $scope.$on(‘$stateChangeSuccess’, function(event, toState, toParams, fromState, fromParams) { if (toState.resolve) { $scope.hideSpinner(); } }); This shows the spinner whenever we are about to go to … Read more

Clear History and Reload Page on Login/Logout Using Ionic Framework

Welcome to the framework! Actually the routing in Ionic is powered by ui-router. You should probably check out this previous SO question to find a couple of different ways to accomplish this. If you just want to reload the state you can use: $state.go($state.current, {}, {reload: true}); If you actually want to reload the page … Read more