我正在尝试使用this库以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 {
}

关于angular - 无法绑定(bind)到“上载器”,因为它不是“div”的已知属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42014268/

10-10 04:40