I have somehow gotten pretty far along with my Angular 2 app without ever actually learning how or when to use custom/third-party directives.
Anyway, I am trying to use ng2-uploader to allow users to upload images with a form and in rc6 I have to declare the directives in my component. According to the docs at the link I provided, I need to simply import UPLOAD_DIRECTIVES to my component's directives property, but I am getting an error saying that directives is not a property of component. That can't be right, can it?
I have the ng2-uploader module and the UPLOAD_DIRECTIVES both imported in app.module.ts, with no errors. If I try to use the directives per the original docs for ng2-uploader, I get:
Unhandled Promise rejection: Template parse errors: Can't bind to 'ng-file-select' since it isn't a known property of 'input'.
I imagine this would be resolved when I can actually get the directives to work.
I feel like I am missing something stupidly obvious. Here are some sections where the problem likely exists.
app.component (irrelevant code omitted):
import { Ng2Uploader, UPLOAD_DIRECTIVES } from 'ng2-uploader';
@NgModule({
imports: [
Ng2Uploader,
],
declarations: [
UPLOAD_DIRECTIVES
],
bootstrap: [ AppComponent ]
})
export class AppModule {}
Component where Directives will be used:
import { UPLOAD_DIRECTIVES } from 'ng2-uploader';
@Component({
selector: "quote-form-partial",
templateUrl: "./app/components/partials/quote-form-partial/quote-form-partial.component.html",
directives: [UPLOAD_DIRECTIVES]
})
uploadFile: any;
hasBaseDropZoneOver: boolean = false;
options: Object = {
url: '/uploads'
};
handleUpload(data): void {
data = JSON.parse(data.response);
this.uploadFile = data;
}
fileOverBase(e:any): void {
this.hasBaseDropZoneOver = e;
}
HTML Template:
<input type="file"
[ng-file-select]="options"
(onUpload)="handleUpload($event)">