I am dealing with an array of objects that contain a "category" attribute. My goal is to filter this array and retrieve only the objects with the "tech" category.
An error message is being displayed stating that "filter" does not exist on type {}
stocks-list.ts
import { Stock } from './Stock';
export const STOCKS: any[] = [
{ id: 11, symbol: 'AAPL', name: 'Apple', category: 'Tech' },
];
stock.service.ts
import { Injectable } from '@angular/core';
import { Stock } from './Stock';
import { STOCKS } from './stocks-list';
@Injectable({
providedIn: 'root'
})
export class StockService {
constructor() { }
techStocks: Stock[];
getTechStocks(): Stock[] {
this.techStocks = STOCKS;
return this.techStocks.filter(xx => xx.category = 'Tech');
}
}