mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Created basic angular-file-upload typings
Not perfect I suspect but a starting point.
This commit is contained in:
parent
b0b4af1223
commit
b5528071bb
@ -13,6 +13,7 @@ All definitions files include a header with the author and editors, so at some p
|
||||
* [AngularFire](https://www.firebase.com/docs/angular/reference.html) (by [Dénes Harmath](https://github.com/thSoft))
|
||||
* [AngularJS](http://angularjs.org) (by [Diego Vilar](https://github.com/diegovilar)) ([wiki](https://github.com/borisyankov/DefinitelyTyped/wiki/AngularJS-Definitions-Usage-Notes))
|
||||
* [angularLocalStorage](https://github.com/agrublev/angularLocalStorage) (by [Hiroki Horiuchi](https://github.com/horiuchi/))
|
||||
* [angular-file-upload](https://github.com/danialfarid/angular-file-upload) (by [John Reilly](https://github.com/johnnyreilly))
|
||||
* [angular-spinner](https://github.com/urish/angular-spinner) (by [Marcin Biegała](https://github.com/Biegal))
|
||||
* [AngularUI](http://angular-ui.github.io/) (by [Michel Salib](https://github.com/michelsalib))
|
||||
* [Angular Hotkeys](https://github.com/chieffancypants/angular-hotkeys/) (by [Jason Zhao](https://github.com/jlz27))
|
||||
|
||||
47
angular-file-upload/angular-file-upload-tests.ts
Normal file
47
angular-file-upload/angular-file-upload-tests.ts
Normal file
@ -0,0 +1,47 @@
|
||||
/// <reference path="angular-file-upload.d.ts" />
|
||||
|
||||
module controllers {
|
||||
|
||||
"use strict";
|
||||
|
||||
var controllerId = "upload";
|
||||
|
||||
class Upload {
|
||||
|
||||
static $inject = ["$upload"];
|
||||
constructor(
|
||||
private $upload: ng.angularFileUpload.IUploadService
|
||||
) {
|
||||
}
|
||||
|
||||
onFileSelect($files: File[]) {
|
||||
//$files: an array of files selected, each file has name, size, and type.
|
||||
var uploads: ng.IPromise<any>[] = [];
|
||||
for (var i = 0; i < $files.length; i++) {
|
||||
var file = $files[i];
|
||||
uploads.push(this.$upload.upload<any>({
|
||||
url: "/api/upload",
|
||||
method: "POST",
|
||||
data: {
|
||||
extraData: {
|
||||
fileName: file.name, test: "anything"
|
||||
}
|
||||
},
|
||||
file: file
|
||||
})
|
||||
.progress((evt: any) => {
|
||||
console.log('progress');
|
||||
})
|
||||
.then(success => {
|
||||
// file is uploaded successfully
|
||||
console.log(success.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
angular.module("app").controller(controllerId, Upload);
|
||||
}
|
||||
26
angular-file-upload/angular-file-upload.d.ts
vendored
Normal file
26
angular-file-upload/angular-file-upload.d.ts
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
// Type definitions for Angular File Upload 1.6.7
|
||||
// Project: https://github.com/danialfarid/angular-file-upload
|
||||
// Definitions by: John Reilly <https://github.com/johnnyreilly>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../angularjs/angular.d.ts" />
|
||||
|
||||
declare module ng.angularFileUpload {
|
||||
|
||||
interface IUploadService {
|
||||
|
||||
http<T>(config: IFileUploadConfig): IUploadPromise<T>;
|
||||
upload<T>(config: IFileUploadConfig): IUploadPromise<T>;
|
||||
}
|
||||
|
||||
interface IUploadPromise<T> extends IHttpPromise<T> {
|
||||
|
||||
progress(callback: IHttpPromiseCallback<T>): IUploadPromise<T>;
|
||||
}
|
||||
|
||||
interface IFileUploadConfig extends ng.IRequestConfig {
|
||||
|
||||
file: File;
|
||||
fileName?: string;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user