可以說我有幾個$資源和一些$ HTTP在我的角度應用:AngularJS - 如何縮放和編碼/解碼base64所有jsons請求?
myApp.factory('Note', function($resource) {
return $resource('http://', {id: '@id'},
{ 'index': { method: 'GET', isArray: true },
'update': { method: 'PUT'},
});
});
與控制器
myApp.controller('NotesController',function NotesController($scope, Note, AuthenticationService) {
$scope.notes = Note.index({}, function(data){
console.log('success, got data: ', data);
$scope.response = "yoy!"
}, function(err){
console.log('error, got data: ', err);
$scope.response = "yay!"
});
});
,並有一定的要求由$ HTTP一樣,直接認證取得
var request = $http.post('http://', {email: email, password: password});
哪裏和我如何告訴角放氣和編碼/解碼JSONs到base64之前的實際請求/響應接收?
我不知道我會包裝外部庫放氣和編碼/解碼到工廠。然後這個工廠會被注入到哪裏? Like $ httpBackend?
謝謝你的回覆。我很想做'$ httpProvider.defaults.transformRequest = function(request){return Base64Factory.encode(request)};'在我的myApp.config(function(){})中,但據我所知我在配置功能中不能注入工廠。你能不能更詳細地幫我解決這個問題?謝謝 –
我也嘗試在myApp.run(function(){})中完成,但仍然沒有成功? –
run()有什麼錯誤? –