diff --git a/README.md b/README.md
index 25a0133c..80aaa66c 100644
--- a/README.md
+++ b/README.md
@@ -43,12 +43,12 @@ npm install ng2-uploader --save
````ts
// app.module.ts
-import { UPLOAD_DIRECTIVES } from 'ng2-uploader/ng2-uploader';
+import { Ng2UploaderModule } from 'ng2-uploader';
...
@NgModule({
...
- declarations: [
- UPLOAD_DIRECTIVES
+ imports: [
+ Ng2UploaderModule
],
...
})
@@ -81,7 +81,7 @@ export class DemoApp {
````html
-
@@ -182,9 +182,9 @@ const upload = {
files.file.forEach((file) => {
let fileData = fs.readFileSync(file.path);
const originalName = file.originalFilename;
- const generatedName = Md5(new Date().toString() +
+ const generatedName = Md5(new Date().toString() +
originalName) + path.extname(originalName);
- const filePath = path.resolve(__dirname, 'uploads',
+ const filePath = path.resolve(__dirname, 'uploads',
generatedName);
fs.writeFileSync(filePath, fileData);
@@ -230,14 +230,14 @@ const path = require('path');
const app = express();
app.use(cors());
-const upload = multer({
+const upload = multer({
dest: 'uploads/',
storage: multer.diskStorage({
filename: (req, file, cb) => {
let ext = path.extname(file.originalname);
cb(null, `${Math.random().toString(36).substring(7)}${ext}`);
}
- })
+ })
});
app.post('/upload', upload.any(), (req, res) => {
@@ -258,7 +258,7 @@ app.listen(10050, () => {
### Backend example using plain PHP
````php
- false,
diff --git a/ng2-uploader.ts b/ng2-uploader.ts
index f2c51aae..68cb03b7 100644
--- a/ng2-uploader.ts
+++ b/ng2-uploader.ts
@@ -1,11 +1,20 @@
-import { NgFileSelectDirective } from './src/directives/ng-file-select';
+import { NgModule } from '@angular/core';
import { NgFileDropDirective } from './src/directives/ng-file-drop';
+import { NgFileSelectDirective } from './src/directives/ng-file-select';
+import { Ng2Uploader } from './src/services/ng2-uploader';
-export * from './src/services/ng2-uploader';
-export * from './src/directives/ng-file-select';
-export * from './src/directives/ng-file-drop';
+@NgModule({
+ declarations: [
+ NgFileDropDirective,
+ NgFileSelectDirective
+ ],
+ providers: [
+ Ng2Uploader
+ ],
+ exports: [
+ NgFileDropDirective,
+ NgFileSelectDirective
+ ]
+})
+export class Ng2UploaderModule{}
-export const UPLOAD_DIRECTIVES: any[] = [
- NgFileDropDirective,
- NgFileSelectDirective
-];
diff --git a/src/directives/ng-file-drop.ts b/src/directives/ng-file-drop.ts
index 2670cef8..9ce5f988 100644
--- a/src/directives/ng-file-drop.ts
+++ b/src/directives/ng-file-drop.ts
@@ -120,12 +120,12 @@ export class NgFileDropDirective {
}
@HostListener('dragover', ['$event'])
- public onDragOver():void {
+ public onDragOver(event:any):void {
this.onFileOver.emit(true);
}
@HostListener('dragleave', ['$event'])
- public onDragLeave():any {
+ public onDragLeave(event:any):any {
this.onFileOver.emit(false);
}
diff --git a/src/directives/ng-file-select.ts b/src/directives/ng-file-select.ts
index 5fe1b2b1..039b6fab 100644
--- a/src/directives/ng-file-select.ts
+++ b/src/directives/ng-file-select.ts
@@ -12,19 +12,19 @@ import { Ng2Uploader, UploadRejected } from '../services/ng2-uploader';
selector: '[ngFileSelect]'
})
export class NgFileSelectDirective {
-
+
@Input() events: EventEmitter;
@Output() onUpload: EventEmitter = new EventEmitter();
@Output() onPreviewData: EventEmitter = new EventEmitter();
@Output() onUploadRejected: EventEmitter = new EventEmitter();
-
+
_options:any;
+ @Input()
get options(): any {
return this._options;
}
- @Input('options')
set options(value: any) {
this._options = value;
this.uploader.setOptions(this.options);