У меня есть angular
factory
, выполняющий некоторую $http
связь с сервером и возвращающий строку. Однако я получаю ошибку Cannot read property 'then' of undefined
. Я прочитал здесь и здесь с похожими проблемами, однако я не смог решить свою проблему.
Это сервисный код:
factory("availabilityService", ['$http', function ($http) {
return {
checkAvailability1: function (element, string) {
// ..... some object creation code ......
$http({
method: 'POST',
url: 'server/server.php',
data: AvailableObj,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(function successCallback(response) {
return response;
}, function errorCallback(response) {
});
}
}
}]);
Внутри controller
:
$scope.checkAvailability = function (element, string) {
availabilityService.checkAvailability1(element, string).then(function (response) { //on this line the error occurs
console.log(response);
});