UI router works fine as long as I'm not using resolve. I fail to understand the tricks. I would appreciate your help in understanding the problem. Following is the code.
var myApp = angular.module('myApp', ['ui.router']);
UI Router in action [Not Working] - Console doesn't print anything.
myApp.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('state1', {
url: '/',
resolve: {
param1: function (RandomFactory) {
console.log('test');
return RandomFactory();
}
},
controller: 'RandomController',
});
$urlRouterProvider.otherwise("/");
}]);
UI Router [Working] - Console prints.
myApp.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('state1', {
url: '/',
resolve: {
param1: function () {
console.log('test');
return "hello";
}
},
controller: 'RandomController',
});
$urlRouterProvider.otherwise("/");
}]);
Factory
myApp.factory('RandomFactory', ['', function () {
return "Hello there";
}])
Controller
myApp.controller('RandomController', ['$scope', function ($scope, param1) {
$scope.param = param1;
}]);
I've gone through the following posts.
- angular-ui router -- inherited resolved dependencies for NAMED dependencies
- Angular ui-router fails to resolve named dependencies
- Angular-ui-router: managing dependencies with resolve
- Promise dependency resolution order in angular ui-router
May be I'm missing something, but I've spent more than 5 hours on this.
Here is a fiddle for this - http://jsfiddle.net/kshitij/NPN7T/8/
Solution
Empty strings in the factory definition was the issue. Though the framework should define an error for this case as it'll help new comers.