I want to make an http request to a Json and this returns an array of comments, from that Array I want to directly get the comments that have an Id that matches the one that happened, all directly:
export class DetailUserComponent implements OnInit {
comments: Comments[];
constructor(
private conexionComment: ConexionCommentsService) { }
ngOnInit() {
this.conexionComment.getCommentsPerson(0)
.subscribe(comments => this.comments = comments);
}
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Comments } from './Class/comments';
@Injectable()
export class ConexionCommentsService {
comments: Comments[];
constructor( private http: HttpClient) { }
getCommentsPerson(id: number): Observable<Comments[]> {
const url = 'assets/Json/listComment.json';
return this.http.get<Comments[]>(url).pipe(find(myComment => this.comments.idUser === id));
}
The idea is to find the object in the Array of objects, the object.idUser === to the id that passed '0' The problem is that when I put this.comments.YA I do not have access to the attributes of the object