1

I recently migrated from ui-router 0.0.1 to 0.2.0. Since the migration, ui-router fails to resolve named dependencies that needs to be injected into a view's controller. Here's the sample code which works fine with ver 0.0.1 but fails in ver 0.2.0

angular.module( 'sample.test', [
 'ui.router',
 'i18nService'
])

.config(function config($stateProvider) {
    $stateProvider.state( 'mystate', {
      url: '/mystate',
      resolve: {i18n: 'i18nService'},
      views: {
        'main': {
          controller: 'MyCtrl',
          templateUrl: 'templates/my.tpl.html'
        }
      }
    });
})

.controller('MyCtrl', ['i18n', function(i18n) {
   // fails to resolve i18n
}]);

i18nService is a simple service that return a promise

angular.module('i18nService', [])
.factory('i18nService', ['$http', '$q', function($http, $q) {
  var deferred = $q.defer();
  $http.get('..').then(..);

  return deferred.promise;
}]);

I get the error "Unknown provider: i18nProvider <- i18n" when using v0.2.0

If i change the resolve config to:

      resolve: {
        i18n: function(i18nService) {
          return i18nService
        }
      },

everything works fine. Is this an expected behaviour, or am I missing some configuration?

Here's the plunker: http://plnkr.co/edit/johqGn1CgefDVKGzIt6q?p=preview

bugs_cena
  • 495
  • 5
  • 11

1 Answers1

2

This is a bug that was fixed last month:

https://github.com/angular-ui/ui-router/commit/4cdadcf46875698aee6c3684cc32f2a0ce553c45

I don't believe it's in any currently released version, but you could either get the latest from github or make the change yourself in your js file. It's simply changing key to value in that one line (you can see it in the github commit).

A workarround is to just not change the name for now.... do

resolve :{
  i18nService: 'i18nService'
}

Then inject i18nService to your controller instead of i18n. It's a bit of a hack, but it does work (it injects the resolved service not the promise).

Daniel Tabuenca
  • 13,147
  • 3
  • 35
  • 38