gpt4 book ai didi

angular - 无法分配给 'GetUserByIdModel',因为它不是变量

转载 作者:搜寻专家 更新时间:2023-10-30 21:55:54 24 4
gpt4 key购买 nike

我正在尝试填充模型,但收到错误无法分配给“GetUserByIdModel”,因为它不是变量。

这是我的模型

export class GetUserByIdModel {
firstname: string;
lastname: string;
nationalityId: number;
identityTypeId: number;
identityValue: string;
titleId: number;
genderId: number;
contactChannels: Array<ContactChannel>;
}

export class ContactChannel {
type: number;
value: string;
}

然后我将它导入到服务文件中并尝试使用它

声明

userDetails: GetUserByIdModel;

函数

  getUserDetails(userId): Observable<GetUserByIdModel> {l
const token = this._storeService.getStoredData().id_token;
const headers = new HttpHeaders()
.set('Authorization', `Bearer ${token}`)
.set('Content-Type', 'application/json');
const options = { headers: headers };
const url = `${this.candidateUrl}/Get/${userId}`;
this._http.get<any>(url, options).subscribe((resp) => {
this.userDetails: GetUserByIdModel = {
firstname: resp.firstname,
lastname: resp.lastname,
nationalityId: resp.firstname,
identityTypeId: resp.identityTypeId,
identityValue: resp.identityValue,
titleId: resp.titleId,
genderId: resp.genderId,
contactChannels: [
{ type: 1, value: resp[0].value },
{ type: 2, value: resp[1].value }
],
};
})

return new Observable((observer) => {
observer.next(this.userDetails);
observer.complete();
});
}

我在这一行看到错误 this.userDetails: GetUserByIdModel = {...

请协助

最佳答案

删除 this.userDetails: GetUserByIdModel -> this.userDetails = {..} 的类型,因为它已经在声明中,并使字段可为空 firstName?, lastName?...

关于angular - 无法分配给 'GetUserByIdModel',因为它不是变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56540249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com