Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2: Can't bind to 'uploader' since it isn't a known property of 'input'

Im trying to integrate ng2-file-upload module into my application.

And im getting this template error: Can't bind to 'uploader' since it isn't a known property of 'input'

UPDATE folder str:

/src/app/app.module.ts

/src/app/components/layout/
                           layout.module.ts
                           other layout components files

                  /category-items
                            category-items.module.ts
                            category-items.component.ts

in layout.module.ts

import { LayoutComponent } from './layout.component';

declarations: [
    LayoutComponent,

in category-items.module.ts

import { CategoryItemsComponent } from './category-items.component';

import {FileUploadModule} from "ng2-file-upload";   

imports: [  ...FileUploadModule ... ]   

app\app.module.ts

 import {FileUploadModule} from "ng2-file-upload";   

 imports: [  ...FileUploadModule ... ]  

app\components\layout\category-items\category-items.component.ts

import { FileUploader } from 'ng2-file-upload';

@Component({
  selector: 'button-view',
  template: `

  <input type="file" class="form-control" name="single" ng2FileSelect [uploader]="uploader" />   

  `
  })

export class ButtonViewComponent implements ViewCell, OnInit {

...
 public uploader:FileUploader = new FileUploader({url:'http://lcoalhost:5000/upload'});

}

@Component({
  selector: 'app-category-items',
  templateUrl: './category-items.component.html',
  styleUrls: ['./category-items.component.scss']
})

export class CategoryItemsComponent implements OnInit {
...
}

Or if i try out like below: i get unexpected closing div tag

<div ng2FileDrop
         (fileOver)-'fileOverBase($event)'
         [uploader]="uploader"
         class="well my-drop-zone">
        Base drop zone
    </div>

I have tried multiple combinations of imports for 'FileUploadModule' in my app.module in various posts, but none seems to work in my case.

Error Stack trace:

"Uncaught (in promise): Error: Template parse errors:↵Can't bind to 'uploader' since it isn't a known property of 'input'. ("↵ ↵

Have googled many posts for solutions for the same:

Some of the references were: (but none helping)

https://github.com/valor-software/ng2-file-upload/issues/418

https://github.com/valor-software/ng2-file-upload/issues/608

like image 484
phyme Avatar asked Jul 25 '17 12:07

phyme


2 Answers

You need to import FileUploadModule in the module that declares the component using 'upload' which in your case would be category-items.module.ts

category-items.module.ts

import { CategoryItemsComponent } from './category-items.component';

import { FileUploadModule } from "ng2-file-upload";   //Should import HERE

imports: [  ...FileUploadModule ... ]   //RIGHT PLACE
like image 165
0mpurdy Avatar answered Oct 31 '22 16:10

0mpurdy


add to app.module.ts this

import { FileSelectDirective } from 'ng2-file-upload';
@NgModule({
    imports: [
        ...
],
    declarations: [
        FileSelectDirective
    ],
    providers: [
        ...
],
    bootstrap: [
        App,
    ],
})

https://github.com/valor-software/ng2-file-upload/issues/418#issuecomment-249865170

Or try to import FIleUploadModule to an each parent module

import { FIleUploadModule } from 'ng2-file-upload';

imports: [
    FIleUploadModule,
    ..........,
    ........,
    ......,

]

It should work.

like image 3
Kishore Peter Avatar answered Oct 31 '22 17:10

Kishore Peter