Struggling to filter an array before feeding data into my Angular component. The array contains hints, but I only want to display one hint initially.
The issue arises when trying to filter the array by a hint that matches the ID of 1. I keep receiving an error stating "'hint' implicitly has an 'any' type." in the CLI, even though it's just a counter.
I have disabled string injection parameters in my tsconfig.json and tried various methods to disable strict TypeScript injection rules, but Angular keeps asking for a type for the counter, preventing me from using the filter function.
import { Component, Input, OnInit } from '@angular/core';
import { SpecsService } from 'src/app/specs.service';
import {Hint} from './hint';
@Component({
selector: 'app-hintbox',
templateUrl: './hintbox.component.html',
styleUrls: ['./hintbox.component.css']
})
export class HintboxComponent implements OnInit {
currentHint: Hint[]=[]
hint: Hint={hint:'',id:0}
constructor(private specsService: SpecsService) { }
ngOnInit(): void {
this.specsService.getHints().subscribe((response)=> this.currentHint= response.filter(hint:Hint => hint.id===1));
}
}
Below is an image of my response object: https://i.sstatic.net/lrL6f.png
Any advice on a more reasonable way to filter the data later would be greatly appreciated. Here is my specs service function, which points to my dummy JSON server:
export class SpecsService {
private apiUrl = 'http://localhost:3000'
constructor(private http:HttpClient) {}
getHints(): Observable<any>{
return this.http.get(`${this.apiUrl}/Hints`)
}
}