我試圖使用this庫來上傳angular2打字稿中的文件。ng2-file-upload:無法讀取未定義的屬性'隊列'
"@angular/core": "^2.3.1", "@angular/compiler-cli": "^2.3.1"
所以,第i個
npm i ng2-file-upload --save
,改變了app.module.ts到:在組件
import { FileUploadModule } from "ng2-file-upload";
@NgModule({
declarations: [
AppComponent,
MenuComponent,
HeaderComponent,
UploaderComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
FileUploadModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我有:
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端的是:
<tr *ngFor="let item of uploader.queue">
,並與抱怨:
Cannot read property 'queue' of undefined
你可以找到源代碼here 只是做一個NPM安裝然後納克服務
我得到了頁面加載錯誤 –
我試過你的代碼,它似乎爲我工作沒有錯誤http: //prntscr.com/e463bp –
thx,我接受你的回答 –