1
ログインシステムの新しいRESTメソッドを作成して、カスタムヘッダーにユーザーの資格情報を提供したいとします。 AngularJS/ng-resourceを使ってどうすればいいですか?私は以下のコードを試しましたが、問題はフォームからユーザー名/パスワードを取得しようとしたときです($ scope.vm.username)。ヘッダーの設定でこれを行うと、これは私に「未定義」を与えます。
angular.module('BkSystemApp.controllers', ['ngResource'])
.controller('LoginController', function($scope, $location, $resource){
//init
$scope.vm = {};
function getUserCredentials(){
return ($scope.vm.username + ':' + $scope.vm.password)
}
//resources
var Authentication = $resource('/users/authentication',{},{
login:{
method: 'GET',
isArray: false,
headers: {'Authentication':btoa(getUserCredentials())}
}
});
//HTTP methods
$scope.login = function(){
Authentication.login(function(data){
});
};
})
ソリューションは機能しましたが、代わりにPOST本体にユーザー名とパスワードを送信します。 – FlowerPower1990