2016-10-21 2 views
1

아직 Angular에 다소 익숙하지만 API 백엔드 (내가 프런트 엔드를 구축 중입니다)를 통해 로그인 요청을 보내려고합니다.Angular 로그인 요청에 -d 추가하기

그래서, API 문서는 다음과 같이이다 :

컬 "URL"-d'user [이메일은 일부 %의 40email.com & 사용자 [비밀번호] = 비밀번호 & 사용자 [password_confirmation] = 암호 '= - X POST \ -H "수락 : 응용 프로그램/무언가를"\ -H "콘텐츠 형식 : 응용 프로그램/x-www-form-urlencoded를"

이 내 형태 :

<form ng-submit='submit()' class='login-form'> 
     <a ng-href='#/signup'><span class='md-text'>Signup</span></a> 
     <span class='md-text'>|</span> 
     <a><span class='md-text'>Forgotten password?</span></a> 
     <input class='login-input' type='text' ng-model='username' placeholder='&#61447; Username'> 
     <input class='login-input' type='password' ng-model='password' placeholder='&#xf023; Password'> 
     <button type="submit" class="btn btn-primary btn-login" ng-model='submit'>Login</button> 
    </form> 

그리고이 내 동료의 일부입니다. ntroller :

$scope.submit=function() { 
    console.log('Submit'); 

    var reqLogin = { 
    method: 'POST', 
    url: 'URL', 
    headers: { 
     'Accept': 'application/blah, 
     'Content-Type': 'application/x-www-form-urlencoded' 
    } 
    } 

    $http(reqLogin).success(function(response) { 
    console.log(response); 
    }); 
} 

이 바보 같은 질문이있을 수 있습니다,하지만 난 각도에서 헤더를 추가 할 알고, 내가 위가 그 JSON 객체에 그렇게.

HTTP 요청에 -d 부분을 어떻게 추가합니까?

답변

-1

jQuery를 혼합 할 때 매개 변수를 넣을 수있었습니다.

 var reqLogin = { 
     method: 'POST', 
     url: 'URL', 
    data: $.params({ 
"user[email]": email, 
"user[password]": password 
)}, 
     headers: { 
      'Accept': 'application/blah, 
      'Content-Type': 'application/x-www-form-urlencoded' 
     } 
     } 
관련 문제