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

◇◆丶佛笑我妖孽 提交于 2019-11-30 13:51:58

问题


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


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/45303404/angular-2-cant-bind-to-uploader-since-it-isnt-a-known-property-of-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!