uploadCSV
在应该发布到端点以上载csv的服务中-我可以在控制台日志中看到csvfile存在,但是当检查network选项卡时,没有显示任何post请求-有什么想法为什么?
import { Injectable } from '@angular/core';
import { ApiService } from "../../../services/api.service";
import { Observable } from "rxjs/Observable";
import { HttpClient } from '@angular/common/http';
@Injectable()
export class BulkuploadService {
constructor(
private http: HttpClient,
private apiService: ApiService,
private userService: UserService
) { }
uploadCSV(csvFile: any): any {
console.log(csvFile);
let formData:FormData = new FormData;
formData.append('file', csvFile, csvFile.name);
console.log(formData);
let url = this.apiService.getApiUrl('bulk-upload/upload');
console.log(url);
return this.http.post(url, formData);
}
}
//组成部分
import { Component,
OnInit,
Inject,
Input,
Output,
EventEmitter,
ElementRef } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import * as moment from 'moment';
import { BulkuploadService } from './bulkupload.service';
@Component({
selector: 'app-bulkupload',
templateUrl: './bulkupload.component.html',
styleUrls: ['./bulkupload.component.scss'],
providers: [
BulkuploadService
]
})
export class BulkuploadComponent implements OnInit {
@Output() closeEvent = new EventEmitter<boolean>();
private postObjects = [];
constructor(@Inject(DOCUMENT) private document: any,
private ref: ElementRef,
public bulkService: BulkuploadService
) { }
uploadCSV(event: any): void {
this.bulkService.uploadCSV(event.target.files[0]);
}
}