Skip to content

Commit

Permalink
Angular 2.2 AoT compiler fixes. create NgModule (bleenco#129)
Browse files Browse the repository at this point in the history
* Fixed bleenco#87, options property is now binded to directive. Using angular 2.2.0.

* Fix ng2 AoT complier errors:

```
dist/tmp/node_modules/ng2-uploader/src/directives/ng-file-drop.ngfactory.ts(64,35): error TS2346: Supplied parameters do not match any signature of call target.
dist/tmp/node_modules/ng2-uploader/src/directives/ng-file-drop.ngfactory.ts(68,35): error TS2346: Supplied parameters do not match any signature of call target.
```

* Declare as a module as per angular 2.x sytle

Fixes AoT compiler issue:
```
Error: Cannot determine the module for class NgFileDropDirective in node_modules/ng2-uploader/src/directives/ng-file-drop.ts!
    at analyzeAndValidateNgModules (node_modules/@angular/compiler/bundles/compiler.umd.js:12707:17)
    at OfflineCompiler.compileModules (node_modules/@angular/compiler/bundles/compiler.umd.js:12775:20)
    at CodeGenerator.codegen (/Users/chuckj/src/angular/modules/@angular/compiler-cli/src/codegen.ts:71:26)
    at codegen (tools/tasks/seed/compile.ahead.prod.ts:13:69)
    at Object.main (/storage/karl/Work/xsact/tools/@angular/tsc-wrapped/src/main.ts:44:12)
    at module.exports (tools/tasks/seed/compile.ahead.prod.ts:39:3)
    at AnonTask.run (tools/utils/seed/tasks_tools.ts:31:18)
    at Gulp.<anonymous> (tools/utils/seed/tasks_tools.ts:60:27)
    at module.exports (node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (node_modules/orchestrator/index.js:273:3)
Compilation failed
```

* update ReadMe for module

* make Ng2UploaderModule name match project
  • Loading branch information
karlhiramoto authored and jkuri committed Nov 19, 2016
1 parent 3424f66 commit 67e60ed
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
...
})
Expand Down Expand Up @@ -81,7 +81,7 @@ export class DemoApp {

````html
<!-- app.component.html -->
<input type="file"
<input type="file"
ngFileSelect
[options]="options"
(onUpload)="handleUpload($event)">
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) => {
Expand All @@ -258,7 +258,7 @@ app.listen(10050, () => {
### Backend example using plain PHP

````php
<?php
<?php

header("Access-Control-Allow-Origin: *");

Expand All @@ -274,7 +274,7 @@ if (isset($_FILES['file'])) {
$ext = '.'.pathinfo($originalName, PATHINFO_EXTENSION);
$generatedName = md5($_FILES['file']['tmp_name']).$ext;
$filePath = $path.$generatedName;

if (!is_writable($path)) {
echo json_encode(array(
'status' => false,
Expand Down
25 changes: 17 additions & 8 deletions ng2-uploader.ts
Original file line number Diff line number Diff line change
@@ -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
];
4 changes: 2 additions & 2 deletions src/directives/ng-file-drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/directives/ng-file-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import { Ng2Uploader, UploadRejected } from '../services/ng2-uploader';
selector: '[ngFileSelect]'
})
export class NgFileSelectDirective {

@Input() events: EventEmitter<any>;
@Output() onUpload: EventEmitter<any> = new EventEmitter();
@Output() onPreviewData: EventEmitter<any> = new EventEmitter();
@Output() onUploadRejected: EventEmitter<UploadRejected> = new EventEmitter<UploadRejected>();

_options:any;

@Input()
get options(): any {
return this._options;
}

@Input('options')
set options(value: any) {
this._options = value;
this.uploader.setOptions(this.options);
Expand Down

0 comments on commit 67e60ed

Please sign in to comment.