I am encountering an error whenever I attempt to download data using a factory method. The factory function is invoked under resolve in app.js
app.js
.state('app.settings', {
url: '/settings',
views: {
'menuContent': {
templateUrl: 'templates/settings.html',
resolve: {
profileData: function (ProfileFactory) {
return ProfileFactory.getProfile();
}
},
controller: 'ProfileCtrl'
}
}
})
Factory.Js
.factory('ProfileFactory', ['$q', '$http', 'localstorage', 'loginSharedData', 'Base64', function ($q, $http, localstorage, loginSharedData, Base64) {
var urlBase = 'http://localhost/snc/Service.Svc/';
var profileData = {};
var deferred = $q.defer();
var promise = deferred.promise;
var _postData = {
"apiKey": Base64.decode(localstorage.get('secureToken')),
"userId": Base64.decode(loginSharedData.userid)
};
profileData.getProfile = function() {
console.log('inside get profile service');
$http({
method: 'POST',
url: urlBase + 'GetUserProfile',
data: JSON.stringify(_postData),
contentType: 'application/json',
dataType: "json"
}).then(function (response) {
deferred.resolve(response.data.GetUserProfileResult);
}, function () {
deferred.reject('Failed to get profile');
});
promise.success = function (fn) {
promise.then(fn);
return promise;
}
promise.error = function (fn) {
promise.then(null, fn);
return promise;
}
return promise;
}
return profileData;
}])
Controllers.js
.controller('ProfileCtrl', ['$scope', 'Base64', 'profileData', function ($scope, Base64, profileData) {
$scope.profile={};
if(profileData.status) {
$scope.profile.email = Base64.decode(profileData.email);
$scope.profile.fullname = Base64.decode(profileData.full_name);
$scope.profile.username = Base64.decode(profileData.user_name);
$scope.profile.emailstatus = profileData.email_status;
}
console.log($scope.profile);
}]);
The Error:
Error: [$injector:unpr] Unknown provider: profileDataProvider <- profileData <- ProfileCtrl
http://errors.angularjs.org/1.3.13/$injector/unpr?p0=profileDataProvider%20%3C-%20profileData%20%3C-%20ProfileCtrl
minErr/<@http://localhost:63342/SNC/www/lib/ionic/js/ionic.bundle.js:8890:12
createInjector/providerCache.$injector<@http://localhost:63342/SNC/www/lib/ionic/js/ionic.bundle.js:12824:19
getService@http://localhost:63342/SNC/www/lib/ionic/js/ionic.bundle.js:12971:39
...
Despite successfully retrieving the data from the service and logging it in the console, this error occurs once the download process completes. Finding the cause of this issue has proven challenging.