Skip to content

Commit f23cd55

Browse files
committed
Merge pull request DefinitelyTyped#4407 from chrismbarr/patch-6
(angular-file-upload) Adding missing a typedef for progress event
2 parents da9a725 + c3125d7 commit f23cd55

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

angular-file-upload/angular-file-upload-tests.ts

+25-23
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,37 @@ module controllers {
1010

1111
static $inject = ["$upload"];
1212
constructor(
13-
private $upload: ng.angularFileUpload.IUploadService
13+
private $upload: angular.angularFileUpload.IUploadService
1414
) {
1515
}
1616

1717
onFileSelect($files: File[]) {
18-
//$files: an array of files selected, each file has name, size, and type.
19-
var uploads: ng.IPromise<any>[] = [];
18+
// $files: an array of files selected, each file has name, size, and type.
2019
for (var i = 0; i < $files.length; i++) {
2120
var file = $files[i];
22-
uploads.push(this.$upload.upload<any>({
23-
url: "/api/upload",
24-
method: "POST",
25-
data: {
26-
extraData: {
27-
fileName: file.name, test: "anything"
28-
}
29-
},
30-
file: file
31-
})
32-
.progress((evt: any) => {
33-
console.log('progress');
34-
})
35-
.then(success => {
36-
// file is uploaded successfully
37-
console.log(success.data);
38-
})
39-
.catch(err => {
40-
console.error(err);
41-
}));
21+
this.$upload.upload({
22+
url: "/api/upload",
23+
method: "POST",
24+
data: {
25+
extraData: {
26+
fileName: file.name,
27+
test: "anything"
28+
}
29+
},
30+
file: file
31+
})
32+
.progress((evt: angular.angularFileUpload.IFileProgressEvent) => {
33+
var percent = parseInt((100.0 * evt.loaded / evt.total).toString(), 10);
34+
console.log("upload progress: " + percent + "% for " + evt.config.file.name);
35+
})
36+
.error((data: any, status: number, response: any, headers: any) => {
37+
console.error(data, status, response, headers);
38+
})
39+
.success((data: any, status: number, headers: any, config: angular.angularFileUpload.IFileUploadConfig) => {
40+
// file is uploaded successfully
41+
console.log("Success!", data, status, headers, config);
42+
});
43+
4244
}
4345
}
4446
}

angular-file-upload/angular-file-upload.d.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Type definitions for Angular File Upload 1.6.7
2-
// Project: https://github.com/danialfarid/angular-file-upload
1+
// Type definitions for Angular File Upload 4.2.1
2+
// Project: https://github.com/danialfarid/ng-file-upload
33
// Definitions by: John Reilly <https://github.com/johnnyreilly>
44
// Definitions: https://github.com/borisyankov/DefinitelyTyped
55

@@ -23,4 +23,9 @@ declare module angular.angularFileUpload {
2323
file: File;
2424
fileName?: string;
2525
}
26-
}
26+
27+
interface IFileProgressEvent extends ProgressEvent {
28+
29+
config: IFileUploadConfig;
30+
}
31+
}

0 commit comments

Comments
 (0)