2016-09-28 5 views
0

하나의 문제에 봉착했습니다. 내 사용자에게 로그인해야하는 메소드가있는 공장에 데이터를 보내고 컨트롤러를 가져 와서 내 끝점에 로그인합니다. 추가 사용을 위해 JWT를 생성하지만, 어떻게 든이 오류가 발생하고 왜 발생하는지 알지 못합니다.정의되지 않은 각도 팩터 리의 'post'속성을 읽을 수 없음

이 문제의 원인은 무엇입니까?

형식 오류 : Object.login (Auth.js : 22)에서 정의되지 않은 의 특성 '게시물을'읽을 수 없습니다. Scope.LoginController에서 $ scope.signIn (LoginController.js : 11) 여기

내입니다 내 종점

'use strict'; 
angular.module("Diplomka").factory('oauth', [function oauth($http) { 
    'use strict'; 
    return { 
     login: function (username, password) { 
      var token = ""; 
      var config = { 
       headers: { 
        "Content-Type": "application/x-www-form-urlencoded" 
       } 
      } 

      var data = { 
       username: username, 
       password: password, 
       grant_type: "password" 
      } 

      $http.post("/Token", data, config) 
       .then(function (response) { 
        token = response.access_token; 
       }); 
     } 
    }; 
}]); 

에 게시 요청에 대한 공장은 여기에 당신은 당신의 "배열 구문은"잘못이 내 컨트롤러

'use strict'; 
app.controller('LoginController', ['$scope', 'oauth', '$location', LoginController]); 
function LoginController($scope, oauth, $location) { 


    $scope.username = ""; 
    $scope.password = ""; 

    $scope.signIn = function() { 
     oauth.login($scope.username, $scope.password); 
    } 

}; 

답변

0

입니다. 서비스 생성자 함수에 매개 변수로 전달하는 변수와 서비스 이름이 일치하지 않습니다.

'use strict'; 
angular.module("Diplomka").factory('oauth', ['$rootScope', '$http', function oauth($scope, $http) { // It should be like this 
    // Rest of your factory here 
}]); 

또한, 나는 그것이 변수 이름 $scope을 사용하여 공장 $rootScope를 주입하는 것이 좋습니다 생각하지 않습니다. 대신 $rootScope라고하고 공장에있는 모든 $scope을 교체하십시오.

'use strict'; 
angular.module("Diplomka").factory('oauth', ['$rootScope', '$http', function oauth($rootScope, $http) { // It should be like this 
    // Rest of your factory here, replacing $scope with $rootScope 
}]); 
+0

오, 내가 바보 같은 실수를 한 것, 감사합니다. – user3188501