Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs 上传大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

xxx.module.ts模块
import { NgModule} from “@angular/core”;
import { FileUploadModule } from “ng2-file-upload” ;
import { XXXComponent } from “./xxx.component”;

@NgModule({
imports:[
FileUploadModule
],
declarations:[
XXXComponent ,/component,pipe,directive/],
providers:[]
})
export class XXXModule{}

xxx.component.ts组件
import { Component} from “@angular/core”;
import { FileUploader} from “ng2-file-upload/file-upload/file-uploader.class”;

@Component({
templateUrl:’xxx.component.html’
})

export class XXXComponent{
constructor(){ }
public fileList;
public uploadFile(event){
this.fileList = event.target.files;
}

//上传
public submitUploadFile(){
if(this.fileList.length>0){
let file:File = this.fileList[0];
let formData = new FormData();
formData.append(‘file’,file,file.name);
let headers = new Headers();
headers.append(‘Accept’,’application/json’);
let options = new RequestOptions({headers:headers});
this.http.post(url,formData,options)
.map(res=>res.json())
.catch(error=>Observable.throw(error))
.subscribe(

//返回上传数据
  • 1
//success or fail
  • 1
)
  • 1
  • 2

}
}
}

xxx.component.html

大佬总结

以上是大佬教程为你收集整理的angularjs 上传全部内容,希望文章能够帮你解决angularjs 上传所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: