christopherthielen / ui-router-extras

THIS PROJECT IS NO LONGER MAINTAINED -- Extras for UI-Router for AngularJS. Sticky States (a.k.a. parallel states), Deep State Redirect (for tab-like navigation), Future States (async state definition)
http://christopherthielen.github.io/ui-router-extras/
MIT License
917 stars 211 forks source link

Comparability problem in $state.get(toState.name).getState() with angular-permission #299

Closed Paragonid closed 8 years ago

Paragonid commented 8 years ago

I get an exception during angular-permission ( https://github.com/Narzerus/angular-permission ) initialization "TypeError: $state.get(...).getState is not a function" after declaring the dependency on 'ct.ui.router.extras' in here:

compensatePermissionMap(statePermissionMap) {
        var permissionMap = new PermissionMap({redirectTo: statePermissionMap.redirectTo});

        var toStatePath = $state
          .get(toState.name) 
          .getState().path // !!! error here
          .slice()
          .reverse();
...

It happens for toState.name == 'login', my route declaration is following:

# CoffeeScript
angular.module 'myModule'
.config ($stateProvider) ->
  $stateProvider
  .state "loginModule",
    abstract: true
    template: "<ui-view/>"
    data:
      permissions:
        only: ['guest']
        redirectTo: 'dashboard'

  .state "login",
    parent: "loginModule"
    url: "/login"
    templateUrl: "login.html"
    controller: "LoginCtrl"

As I understand, ui-router-extras changes something in the .getState() leading to this exception, can anyone suggest a way to solve it?

Paragonid commented 8 years ago

Switching these lines in module dependency fixes it:

angular.module('module', [
  'ui.router'
  'permission' # error
  'ct.ui.router.extras'
])
angular.module('module', [
  'ui.router'
  'ct.ui.router.extras'
  'permission' # no error
])

Discussion here https://github.com/Narzerus/angular-permission/issues/185