0

我正在使用 Angular 6 开发一个 Web 应用程序。这是我的文件夹结构。应用 | 页 | 仪表板 | 地图

在地图组件中,我正在使用“ng2-file-upload”上传文件。这是我的“maps.component.html”

 <form #mapsForm="ngForm" enctype="multipart/form-data">
      <div class="form-group">
        <label for="name">Name</label>
        <div class="input-group">
          <input id="mapName" class="form-control" name="mapName"  >
        </div>

        <br>

        <label for="geoRefMap">Geo- reference Map</label>
        <div class="input-group">

         <input type="file"  #fileInput name="milespec"  
         class="form-control"
         ng2FileSelect
         [uploader]="uploader" 
         (change)="handleFileInput($event.target.files)" />
          <img src="../../../../../assets/images/maps/Browse.png" width="40" height="40" style=" position: absolute; top: 1px; right: 1px"  onclick="openfileDialog();"/>
        </div>
        <br>
    </form>

我在 maps.component.ts 文件中使用了“FileUploader”。

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

export class MapsComponent implements OnInit {

  public uploader:FileUploader = new FileUploader({url: URL});
}

但它给了我以下错误。

Uncaught (in promise): Error: Template parse errors:
Can't bind to 'uploader' since it isn't a known property of 'input'. ("
         class="form-control"
         ng2FileSelect 
         [ERROR ->][uploader]="uploader" 
         (change)="handleFileInput($event.target.files)" />
          <!-- <in"): ng:///DashboardModule/MapsComponent.html@23:9
Error: Template parse errors:

我在这里尝试了几种解决方案' https://github.com/valor-software/ng2-file-upload/issues/418 '但没有奏效。我尝试不时将“FileSelectDirective”添加到所有父模块中。但没有奏效。有没有人有任何解决方案?

4

1 回答 1

1

我有这个问题。我所要做的就是在我的app.module.ts(或你的子模块)中,添加

 declarations: [
     ...
     FileSelectDirective
  ],
于 2018-12-20T15:57:08.943 回答