Urlrouter resolve variable unknown provider

Have just started using resolve in urlRouterProvider to ensure that database query has completed before changing to the view where the query results are displayed. Overall application is based on standard side-menu template.

.config(function($stateProvider, $urlRouterProvider) {

    .state('app', {
        url: "/app",
        abstract: true,
        templateUrl: "templates/menu.html",
        controller: 'AppCtrl'

    .state('app.emergencycontacts', {
        url: "/emergencycontacts",
        views: {
            'menuContent': {
                templateUrl: "templates/emergencycontacts.html",
                controller: 'EmergencyContactsCtrl',
                resolve: {
                	emergencyContacts: function(EmergencyContactsService) {
                		return EmergencyContactsService.getEmergencyContacts();

The changes to the standard template are derived from studying multiple posts on the topic.

In my controller I have the following code:

.controller('EmergencyContactsCtrl', function($scope, EmergencyContactsService, emergencyContacts) {
    $scope.emergencyContacts = emergencyContacts;
//    EmergencyContactsService.getEmergencyContacts().then(function(emergencyContacts) {
//	    $scope.emergencyContacts = emergencyContacts;
//    })

When running this code, it fails with the following message:

Error: [$injector:unpr] Unknown provider: emergencyContactsProvider <- emergencyContacts

If I don’t attempt to pass the resolve variable and just rerun the query in the controller then everything works fine.

Any idea as to what I’m doing wrong? I have tried placing the resolve outside the view definition but behaviour is exactly the same.


Found the problem.

I had an “ng-controller” attribute set on the “ion-content” tag in the html.

Glad to see you got this resolved :smile:

Can any one help me about this problem? I spend 2h on it but still challenging me.

ionic.bundle.js:13438 Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:unpr] Unknown provider: $stateProvider

1 Like

Did you fix your error? I am getting same error …