I am creating a service to download data from WCF service and then I am binding it to the ionic view. I am not able to bind the data to the view, I keep getting error "profileData is undefined", I have tried to follow the ionic online tutorial.
Inside of config
.state('app.settings', {
url: '/settings',
views: {
'menuContent': {
templateUrl: 'templates/settings.html',
controller: 'ProfileCtrl'
}
},
resolve: {
profileData: function(ProfileService){
return ProfileService.getUserProfile()
}
}
})
Profile service
.service('ProfileService', function ($q, $http, $localstorage, loginSharedData, Base64) {
return {
getUserProfile: function () {
console.log('inside service');
var deferred = $q.defer();
var promise = deferred.promise;
var _postData = {
"apiKey": Base64.decode($localstorage.get('secureToken')),
"userId": Base64.decode(loginSharedData.userid)
};
setTimeout(function(){
$http({
method: 'POST',
url: 'http://localhost/snc/Service.Svc/GetUserProfile',
data: _postData,
contentType: 'application/json',
dataType: "json"
}).then(function (response) {
console.log('inside service success');
var _data = response.data;
if (_data.GetUserProfileResult.status) {
console.log('Profile downloaded');
deferred.resolve(_data.GetUserProfileResult);
}
else
deferred.reject('Failed to get profile.');
}, function (response) {
console.log('inside profile service fail');
console.log(response);
if (response.status == 0) {
deferred.reject('Failed to get profile');
}
})}, 1000);
promise.success = function (fn) {
promise.then(fn);
return promise;
}
promise.error = function (fn) {
promise.then(null, fn);
return promise;
}
return promise;
}
}
})
The Controller
.controller('ProfileCtrl', function ($scope, ProfileService, Base64) {
$scope.profileData = profileData;
}
The profileData is undefined in the controller, can you point to the error?