My objective is to filter specific data from a database and display it on the page. I planned to utilize the httpClient get method in the service to retrieve only the desired data. However, I am unsure about how to effectively handle the filtering process.
Currently, I am able to fetch all the available data through a testurl but I need assistance with filtering out the specific entries.
data.json
[
{"allOrders":21},
{"pendingConfirmOrders":14},
{"pendingPaymentOrders":8}
]
order-history.component.ts
import { orderHistoryService } from './../../infrastructure/services/order-history.service';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-order-history-page',
templateUrl: './order-history-page.component.html',
styleUrls: ['./order-history-page.component.scss']
})
export class OrderHistoryPageComponent implements OnInit {
orderHistory:any;
confirmOrder;
constructor(private orderService:orderHistoryService) {
this.orderService.getOrderHistory().subscribe((response:any)=>{
this.orderHistory = response;
});
}
_orderHistory(){
console.log(this.orderHistory);
}
_pendingConformation(){
this.confirmOrder=this.orderHistory.filter(orders=> this.orderHistory
.includes(this.confirmOrder));
}
ngOnInit() {
}
}
orderService.ts
import { Injectable } from '@angular/core';
import { AppSettings } from '../../app.setting';
import { ApiService } from './api.service';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class orderHistoryService {
private testUrl='../../../assets/data/orders.json';
// _baseUrl = AppSettings.BACKEND2_SUBSCRIBE_BASE;
constructor(private _apiService: ApiService, private _http: HttpClient) { }
getOrderHistory():Observable<any>{
return this._http.get<any>(this.testUrl);
// const endpoint = `${AppSettings.SERVER_API}`//endpoint;
// return this._http.get(endpoint);
}
/**
* THIS METHOD GET The history of orders
*/
}
The functions I have implemented currently result in an empty array being returned.