I encounter an issue while attempting to populate a particular model, receiving the error "Cannot assign to 'GetUserByIdModel' because it is not a variable."
Here is the model in question:
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;
}
After importing the model into a service file, I encounter issues with its usage.
Declarations:
userDetails: GetUserByIdModel;
Function:
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();
});
}
The error point is specifically on this line
this.userDetails: GetUserByIdModel = {...
Your assistance would be greatly appreciated