Urlrouter resolve variable unknown provider


#1

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) {
    $stateProvider

    .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.

THANKS
Peter


#2

Found the problem.

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


#3

Glad to see you got this resolved :smile:


#4

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


#5

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