onFileChangedForCV(event) {
this.details.= event.target.files[0]
}
candidateDetails(){
let formData = new FormData();
let photo= formData.append('profile_pic',this.details.photo);
let name=this.details.name;
let age = this.details.age;
let cv = this.details.cv;
let experience = this.details.experience;
let current_salary = this.details.current_salary;
let expected_salary = this.details.expected_salary;
let notice_period = this.details.notice_period;
if (this.contentEditable){
this.detaisservice.candidateDetailsExperienced(photo(Here throwing ERROR),name,age,cv,experience,current_salary,expected_salary,notice_period)
.subscribe(
data => {
this.details.DetailsResponse = data;
if(this.details.DetailsResponse.code =='200'){
}
},
error => alert(error),
() => console.log(this.details.DetailsResponse)
);
}
}
candidateDetailsFresher(photo:string,name:string,age:string,cv:string){
let body = JSON.stringify({photo:photo,name:name,age:age,cv:cv});
let headers = new Headers({ 'Content-Type': 'application/json'});
let options = new RequestOptions({ headers: headers });
console.log(body);
console.log(options);
return this.http.post('http://127.0.0.1:8000/api/seeker/candidate_details/', body, options)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
let body = res.json();
return body || [];
}
private handleError (error: any) {
return Observable.throw(error.json().error || 'Server error');
}
错误:类型'void'的参数不能分配给'字符串'类型的参数。当我尝试在Angular 6中调用API时显示错误。请帮助我解决此错误。例如:let photo = this.details.photo; (它正常工作,但我想作为FormData发送)。
答案 0 :(得分:0)
的问题
let photo= formData.append('profile_pic',this.details.photo);
append
的FormData函数返回void
,因此基本上您的变量photo
在这里是空的,并且您试图将void
的值传递给candidateDetailsExperienced
期望它是string
。
因此,更改类型为string
的照片变量。我猜您可以改用this.details.photo
。
您可以中断此行
let photo= formData.append('profile_pic',this.details.photo);
到
formData.append('profile_pic',this.details.photo);
let photo = this.details.photo; //<-- you can change to other string value if reuqired.