Having trouble with Angular UI router? When returning a factory in resolve, why is the controller receiving undefined? What could be causing this issue?
It works with string: When I return a simple string in the resolve function, I am able to get data in the controller.
Factory call
app.factory('LogHomService', function(Service1, Service2) {
return {
MyService: function(data) {
Service1.log("user", encodeURIComponent("ad"))
.then(function(response) {
var FullUrl = response.strURL;
var objs = response.products;
Service2.pageLoad(objs)
.then(function(response) {
var homeScreen = response;
data(homeScreen);
});
});
},
};
});
With UI router:
.state('home.prod', {
url: '/product',
views: {
'@': {
templateUrl: baseUrl + 'home/product',
controller: 'productController'
}
},
resolve: {
param2: function(LogHomService) {
return LogHomService.MyService();
}
}
})
And in the Controller:
var productController = function ($scope, $rootScope, $state, $stateParams,param2)
{
console.log(param2); // This logs as undefined
}
CashController.$inject = ['$scope', '$rootScope', '$state','$stateParams','param2');