$ bower install angular-request --save<script type="text/javascript" src="angular-request.js"></script>// add 'angular-request'
var app = angular.module('myApp', ['angular-request']);// use $httpRequest
app.controller('IndexController', ['$httpRequest', function($httpRequest) {
// ~~ code
}]);- url - string
- param - object|null
- callback - function
- error - boolean
- httpResponse - object
- body - (data)
$httpRequest.post('http://api.example/url', params, function(error, httpResponse, body) {
// ~~ code
});- url - string
- param - object|null
- callback - function
- error - boolean
- httpResponse - object
- body - (data)
$httpRequest.get('http://api.example/url', params, function(error, httpResponse, body) {
// ~~ code
});- url - string
- param - object|null
- callback - function
- error - boolean
- httpResponse - object
- body - (data)
$httpRequest.upload('http://api.example/url', params, function(error, httpResponse, body) {
// ~~ code
});- create directive (e.g. 'inputFileSetter')
app.directive('inputFileSetter', [function()
{
return {
restrict: 'A',
scope: { model: '=inputFileSetter' },
link: function(scopes, elements, attrs) {
var element = elements[0];
var setFile = function() {
scopes.$apply(function() {
scopes.model = (element.files[0]) ? element.files[0] : null;
});
};
if (element.addEventListener) {
element.addEventListener('change', setFile);
} else if (element.attachEvent) {
element.attachEvent("onchange", setFile);
}
}
};
}]);- set directive in input tag as attribute (input-file-setter="")
<input type="file" input-file-setter="self.files.model">