I am trying to do something very similar to the $http service. From my understanding $http return a promise object.
When using it the syntax is :
$http(.
You need to use the $q service and create and return your own promise in GetUserProfile:
function GetUserProfile() {
var deferred = $q.defer();
var promise = deferred.promise;
// success condition
if (!true) {
deferred.resolve('data');
// error condition
} else {
deferred.reject('error');
}
promise.success = function(fn) {
promise.then(fn);
return promise;
}
promise.error = function(fn) {
promise.then(null, fn);
return promise;
}
return promise;
}
GetUserProfile()
.success(function(data) {
console.log(data);
})
.error(function(error) {
console.error(error);
});