Quick question, would I need to unsubscribe the subscription contained here since it's not in the constructor?
import { Component, OnInit } from '@angular/core';
import { HttpService } from "./services/http.service";
import { Main } from "./interfaces/data-interface";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
constructor(private httpService: HttpService) {
}
mainData: Main;
itemIndexFocus: number = 0;
ngOnInit() {
this.httpService.getFighterDetail()
.subscribe((res) => {
this.mainData = res.body;
console.log(this.mainData);
});
}
getImage() {
return this.mainData.matches[this.itemIndexFocus].image;
}
}
The httpservice file looks like this:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Observable } from 'rxjs';
@Injectable()
export class HttpService {
constructor(private http: HttpClient) { }
getFighterDetail(): Observable<any> {
return this.http.get("/MYAPI", { responseType: 'json', observe: 'response' })
}
}