ui-router resolve with dynamic parameters

You were close with $routeParams. If you use ui-router use $stateParams instead. This code works for me: .state(‘recipes.category’, { url: ‘/:cat’, templateUrl: ‘/partials/recipes.category.html’, controller: ‘RecipesCategoryCtrl’, resolve: { category: [‘$http’,’$stateParams’, function($http, $stateParams) { return $http.get(‘/recipes/’ + $stateParams.cat) .then(function(data) { return data.data; }); }] } })

Angularjs ui-router. How to redirect to login page

The point is, do not redirect if not needed === if already redirected to intended state. There is a working plunker with similar solution .run(function($rootScope, $location, $state, authenticationSvc) { $rootScope.$on( ‘$stateChangeStart’, function(e, toState , toParams , fromState, fromParams) { var isLogin = toState.name === “login”; if(isLogin){ return; // no need to redirect } // now, … Read more

AngularJS – UI Router – programmatically add states

See -edit- for updated information Normally states are added to the $stateProvider during the config phase. If you want to add states at runtime, you’ll need to keep a reference to the $stateProvider around. This code is untested, but should do what you want. It creates a service called runtimeStates. You can inject it into … Read more

Angular ui-router: ui-views vs directives?

How about if you used Angular UI router’s inline views to point to directives? Let’s say you have a directive for a table that handles CRUD operations on user accounts. We’ll say the directive is named user-admin. Our routes file would look like: .state(‘users’, { url: “https://stackoverflow.com/users”, template: “<user-admin>” }); This would give you many … Read more

Angular ui-router – how to access parameters in nested, named view, passed from the parent template?

The instanceID is declared as an parameter, so we can access it like this .controller(‘ViewWorklogCrtl’, [ ‘$scope’,’$stateParams’ function($scope , $stateParams ) { // $scope.instanceID = $stateParams.instanceID; … All the other details could be found here https://github.com/angular-ui/ui-router/wiki/URL-Routing And the call to ui-sref should be like this <a ui-sref=”instance-ticket.worklog({ instanceID:ticket.testnum })” >.. Extend: In case that we … Read more

Angular 2 How to detect back button press using router and location.go()?

I don’t know if the other answers are dated, but neither of them worked well for me in Angular 7. What I did was add an Angular event listener by importing it into my component: import { HostListener } from ‘@angular/core’; and then listening for popstate on the window object (as Adrian recommended): @HostListener(‘window:popstate’, [‘$event’]) … Read more

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

What’s the proper way to set a Router & RouterLink in Angular2 Dart

As of Angular Dart 2.0.0 (release candidate), the correct syntax for a router link is: <a [router-link]=”[‘./Home’]”>Go Home</a> The value is a list of arguments that are passed to Router.navigate(). The correct syntax for configuring routes is: @Component( selector: ‘my-app’, template: …, directives: const [ROUTER_DIRECTIVES], providers: const [HeroService, ROUTER_PROVIDERS]) @RouteConfig(const [ const Route( path: ‘/dashboard’, … Read more

Angular ui-router scroll to top, not to ui-view

Another approach is to decorate the default $uiViewScroll service, effectively overriding the default behaviour. app.config(function ($provide) { $provide.decorator(‘$uiViewScroll’, function ($delegate) { return function (uiViewElement) { // var top = uiViewElement.getBoundingClientRect().top; // window.scrollTo(0, (top – 30)); // Or some other custom behaviour… }; }); }); And as Hubrus mentioned, for any <ui-view> you do not wish … Read more