I have this interface with nested array inside:
import { IEmitente } from './ICustomer';
export interface IAccounts {
current_page: number;
data: ICustomer[];
first_page_url: string;
from: number;
last_page: number;
last_page_url: string;
next_page_url: string;
path: string;
per_page: number;
prev_page_url: string;
to: number;
total: number;
}
the customer interface is like this:
export interface ICustomer {
id: number;
name: string;
federalId: string;
firstBuy: date;
balance: number;
}
I have this http get method on service:
getContas(identific,search,page?): Observable<IAccounts[]> {
return this.httpClient.get<IAccounts[]>(`${this.BASE_URL}/getContas?identific=${identific}&search=${search}&page=${page}`)
}
the observable is look like this:
{current_page: 1, data: Array(15), first_page_url: "https://web.gruposol.com.br/endpoint/api/getContas?page=1", from: 1, last_page: 19, …}
current_page: 1
data: (15) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
first_page_url: "https://address/api/getContas?page=1"
from: 1
last_page: 19
last_page_url: "https://address/api/getContas?page=19"
next_page_url: "https://address/api/getContas?page=2"
path: "https://address/api/getContas"
per_page: 15
prev_page_url: null
to: 15
total: 275
__proto__: Object
how can I get only data (customers) part from observable using rxjs?
I need some like this:
on a variable customers:ICustomer[] = [];
I'd like to receive only data array from observable. How can I do that?
currently my ngOnInit method is like this:
ngOnInit() {
this.AlvosService.getContas(this.identific, this.search)
.subscribe((response) => { console.log(response)} ),
(error) => { console.log(error); };
}