This repository has been archived by the owner on Mar 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Introduction
Dennis edited this page Feb 12, 2017
·
1 revision
Here your find the most important code lines for your integration in your own @angular
project. With this uploader you get the possibility to hook into the or to overwrite uploader functions. Based on your way to write code.
- Introduction
- Module API
- FAQ - (still waiting for questions)
Here are some example code lines which are often used by user.
npm install @uniprank/ng2-file-uploader --save
import { FileUploaderModule } from '@uniprank/ng2-file-uploader';
@NgModule({
declarations: [ ],
imports: [
FileUploaderModule
],
exports: [ ]
})
export class ExampleModule {
}
import { FileUploader } from '@uniprank/ng2-file-uploader';
export class ExampleComponent {
public uploader: FileUploader;
constructor () {
// Bind FileUploader class to variable
this.uploader = new FileUploader({
// API url to call
url: 'https://uniprank.github.io/ng2-file-uploader/example/'
});
}
}
<!-- HTML for ExampleComponent -->
<div>
<input type="file" ng2File2Select [uploader]="uploader" />
</div>
<div>
<input type="file" ng2File2Select [uploader]="uploader" multiple />
</div>
<div>
<div ng2File2Drop [uploader]="uploader"></div>
</div>
import { Transfer, FileUploader, FileFilter, hookType, UploaderHook } from '@uniprank/ng2-file-uploader';
export class ExampleComponent {
public uploader: Transfer;
public hasFiles: boolean;
constructor () {
// Bind FileUploader class to variable
this.uploader = new FileUploader({
// API url to call
url: 'https://uniprank.github.io/ng2-file-uploader/example/',
removeBySuccess: false,
autoUpload: false,
// filter implementation possible
filters: [
new FileFilter('only:JPG', new RegExp('image/jpeg'), 'type')
]
});
// Hook implementation if needed
this.uploader.hook(new UploaderHook(
// define hook type
hookType.successUploadFile,
// callback function
function(response: any, status: any, headers: any){
console.log(response, status, headers);
},
// priority number 0 is low. number > 0 is higher
0
));
// Subscribe to queue (async) to get the current queue length
this.uploader.queue$.subscribe((data: any) => {
this.hasFiles = (data.length > 0);
});
}
}
build by denfie