Skip to content

psychedelicnekopunch/angular-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-request

Install

$ bower install angular-request --save

Usage

<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
}]);

Method

$httpRequest.post(url, param, callback)

  • 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
});

$httpRequest.get(url, param, callback)

  • 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
});

$httpRequest.upload(url, param, callback)

  • 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
});

input[type="file"]

  • 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">

About

$http wrapper

Resources

Stars

Watchers

Forks

Packages

No packages published