I am working with two Observables, employee$ and personalInformation$. The personalInformation$ Observable is a subset of employee$ and I need to map the matching properties from employee$ to personalInformation$. Although both observables have many more fields, I have simplified them here for clarity.
export interface EmployeeModel {
id: number;
personalEmail: string;
firstName: string;
lastName: string;
remote: boolean;
office: string;
}
employee$: Observable<EmployeeModel>;
Personal Information
export interface PersonalInformationModel {
id: number;
personalEmail: string;
firstName: string;
lastName: string;
}
personalInformation$: Observable<PersonalInformationModel>;
This was my initial attempt which did not yield the desired result.
this.personalInformation$ = this.employee$
.pipe(
map((data) => ({
id: data!.id,
personalEmail: data!.personalEmail,
firstName: data!.firstName,
lastName: data!.lastName
})),
catchError(err => {
const message = "Could not load record";
this.logService.error(message, err)
return throwError(() => new Error(err));
})
);