繁体   English   中英

无法绑定到“上载器”,因为它不是“ div”的已知属性

[英]Can't bind to 'uploader' since it isn't a known property of 'div'

我正在尝试使用库在angular2 CR5打字稿中上传文件。 我正在使用角度"version": "1.0.0-beta.16"

所以,首先我

npm i ng2-file-upload --save

在组件中,我有:

import { Component } from '@angular/core';
import { FileUploader } from 'ng2-file-upload';

// const URL = '/api/';
const URL = 'https://evening-anchorage-3159.herokuapp.com/api/';

@Component({
  selector: 'app-simple-demo',
  templateUrl: './simple-demo.component.html',
  styleUrls: ['./simple-demo.component.css']
})
export class SimpleDemoComponent {
  public uploader:FileUploader = new FileUploader({url: URL});
  public hasBaseDropZoneOver:boolean = false;
  public hasAnotherDropZoneOver:boolean = false;

  public fileOverBase(e:any):void {
    this.hasBaseDropZoneOver = e;
  }

  public fileOverAnother(e:any):void {
    this.hasAnotherDropZoneOver = e;
  }
}

组件的html端的一部分是:

          <div ng2FileDrop
                 [ngClass]="{'nv-file-over': hasBaseDropZoneOver}"
                 (fileOver)="fileOverBase($event)"
                 [uploader]="uploader"
                 class="well my-drop-zone">
                Base drop zone
            </div>

它抱怨:

Can't bind to 'uploader' since it isn't a known property of 'div'. ("s': hasAnotherDropZoneOver}"
                 (fileOver)="fileOverAnother($event)"
                 [ERROR ->][uploader]="uploader"
                 class="well my-drop-zone">
                Another drop zone
"): AppComponent@33:17

解决的办法是将我的角度更新到最新版本。

然后将以下内容添加到app.module文件中:

import { FileUploadModule } from "ng2-file-upload";
//...
@NgModule({
    imports: [
        //...,
        FileUploadModule
    ],
    declarations: [],
    providers: []
})
export class ObjektinfoModule {
}

有时您需要使用(uploader)而不是方括号[uploader]来正确绑定属性。 很奇怪,但是为我解决了这个问题。

解决方案只是将FIleUploadModule导入到主模块中。

import { FileUploadModule } from 'ng2-file-upload'
...
imports: [
...
FileUploadModule
],

问题不仅在于导入,还在于模板:

请尝试在component.html文件中初始化以下内容(上载程序)。

而不是[uploader]="uploader":

             <div ng2FileDrop
                   [ngClass]="{'nv-file-over': hasBaseDropZoneOver}"
                   (fileOver)="fileOverBase($event)"
                   [uploader]="uploader"
                   (onFileDrop)="onFileSelected($event)"
                   class="well my-drop-zone">
                  Base drop zone
              </div> 

添加(uploader)="uploader":

                <div ng2FileDrop
                   [ngClass]="{'nv-file-over': hasBaseDropZoneOver}"
                   (fileOver)="fileOverBase($event)"
                   (uploader)="uploader"
                   (onFileDrop)="onFileSelected($event)"
                   class="well my-drop-zone">
                  Base drop zone
              </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM