Prior to getting the current customer orders I need to return his name, so my related Service class part looks like the following:
Updated:
export class AuthService {
customerNameUrl = 'customers/name/' + name;
. . .
getCustomerOrders(customerName: string): Observable<CustomerOrder[]> {
let currentCustomerName = this.getCurrentCustomer(customerName).subscribe(customer => customer.name);
console.log(currentCustomerName); <--- Error
let customerOrders = this.http.get<CustomerOrder[]>(this.customerOrdersUrl);
console.log(customerOrders);
return customerOrders
}
getCurrentCustomer(name: string): Observable<Customer> {
const url = this.customerNameUrl;
return this.http.get<Customer>(url).pipe(
tap(_ => this.log(`fetched customer name=${name}`, 'success')),
catchError(this.handleError<Customer>(`getCustomer name=${name}`))
);
}
. . .
}
But the first console.log shows subscribers instead of the required value. I have tried to add map operator to get only the name from the entity but didn't succeed, maybe added it in the wrong way, any idea?