title: "defer undefined" in AngularJS
body: <pre><code>.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("&amp;");
            },
            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"];
            });
          })
        }
      ])
  </code></pre>
  
  <p>Hi, I'm new in Angular JS and I have the following error: <code>TypeError: Cannot read property 'defer' of undefined</code>.</p>
  
  <p>How can we fix this?</p>