'Filter an array based on the values of another array (Angular)
I'm not really sure if this is the right approach. I've got two post calls, that return different attributes. The second call is supposed to return articles that have the same value as the articleNumbers from the first call. This is what I do on the component.ts. I use flatMap, to return all articleNumbers that are displayed on the page and make the second call based on the returned arrays.
getInventory() {
if (this.masterArticle) {
const inventory = this.allArticleVariantsByColor.flatMap(v =>{return v.articleVariants}).map(v=> {return Number (v.articleNumber)})
const subscription: Subscription = this.inventoryService.getInventory(inventory)
.subscribe(apiResponse => {
this._inventoryService = apiResponse.data as ArticleVariantsByColor[];
});
this.subscriptions.push(subscription);
}
}
This works and I get this.
{
"statusCode": 200,
"data": [
{
"article": 1000207054,
"ownStock": 4,
"supplierStock": 32,
"notice": null,
"nextAvailability": null,
"hasMoreOwnStock": false,
"ownStockText": "4"
},
{
"article": 1000207055,
"ownStock": 5,
"supplierStock": 46,
"notice": null,
"nextAvailability": null,
"hasMoreOwnStock": false,
"ownStockText": "5"
}
]
}
Now I need to display these values which doesnt work and I assume that I need to filter these responses based on the articleNumbers from the first call because these values are only supposed to be shown when the use clicks a certain size/color combination. How would I go about filtering these values in angular?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
