.controller('LoginConnect', ['$scope', 'connecting',
function($scope, connecting){
$scope.user = {};
$scope.connect = function($scope, $q){
connecting();
};
}
])
.factory("connecting", [ function($scope,$q, $http){
var deferred = $q.defer();
$http({
method: 'POST',
url: "http://api.tiime-ae.fr/0.1/request/login.php",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: {login: $scope.user.login, password: $scope.user.password}
})
.success(function(result){
deferred.resolve(result);
var promise = deferred.promise;
promise.then(function(result){
jsonTab = angular.fromJson(result);
$scope.result = result["data"];
$scope.user.token = result["data"];
});
})
}
])
Hi, I'm new in Angular JS and I have the following error: TypeError: Cannot read property 'defer' of undefined.
How can we fix this?