[英]Argument of type 'void' is not assignable to parameter of type 'string' in Angular 6
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');
}
Error:Argument of type 'void' is not assignable to parameter of type 'string'. 错误:类型“ void”的参数无法分配给类型“ string”的参数。 It's showing error when i am trying to call API in Angular 6 .Please help me to resolve this error.Ex:let photo = this.details.photo; 当我尝试在Angular 6中调用API时显示错误。请帮助我解决此错误。例如:let photo = this.details.photo; (it working but i want to Send as FormData). (它的工作,但我想作为FormData发送)。
The issue with 与问题
let photo= formData.append('profile_pic',this.details.photo);
append
function of FormData returns void
so basically your variable photo
is void here and you are trying to pass the void
value to candidateDetailsExperienced
however it is expecting it to be string
. FormData的append
函数返回void
因此,基本上,您的可变photo
在此处为void,并且您正在尝试将void
值传递给candidateDetailsExperienced
但是期望它是string
。
So change your photo variable of type string
. 因此,更改您的string
类型的照片变量。 I guess you can use this.details.photo
instead. 我想您可以改用this.details.photo
。
You can break this line 你可以打破这条线
let photo= formData.append('profile_pic',this.details.photo);
to 至
formData.append('profile_pic',this.details.photo);
let photo = this.details.photo; //<-- you can change to other string value if reuqired.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.