16

我试图将 ng2-file-upload 模块集成到我的应用程序中。

我收到此模板错误:无法绑定到“上传器”,因为它不是“输入”的已知属性

更新文件夹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

在 layout.module.ts

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

declarations: [
    LayoutComponent,

在类别-items.module.ts

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

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

imports: [  ...FileUploadModule ... ]   

应用\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 {
...
}

或者如果我尝试如下:我得到意外的关闭 div 标签

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

我已经在我的 app.module 中的各种帖子中尝试了多种导入“FileUploadModule”的组合,但在我的情况下似乎没有一个有效。

错误堆栈跟踪:

“未捕获(承诺):错误:模板解析错误:↵无法绑定到“上传器”,因为它不是“输入”的已知属性。(“↵ ↵

在谷歌上搜索了许多相同的解决方案:

一些参考是:(但没有帮助)

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

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

4

2 回答 2

38

您需要导入FileUploadModule声明组件的模块,'upload'在您的情况下使用该组件category-items.module.ts

类别-items.module.ts

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

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

imports: [  ...FileUploadModule ... ]   //RIGHT PLACE
于 2017-07-25T14:29:34.970 回答
3

添加到 app.module.ts 这个

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

或者尝试将 FIleUploadModule 导入到每个父模块

从 'ng2-file-upload' 导入 { FIleUploadModule };

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

]

它应该工作。

于 2019-05-22T06:22:46.767 回答