When I am trying to initialise a variable 'products' as any[], the error is being showed as 'Property 'products' has no initializer and is not definitely assigned in the constructor' . My code is given below. Please help to fix
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'Skinet';
products: any[]; // Error is coming here
constructor(private http: HttpClient){}
ngOnInit(): void {
this.http.get('https://localhost:5001/api/products').subscribe((Response: any) => {
this.products = Response.data;
console.log(Response.data);
}, error => {
console.log("Erro");
console.log(error);
})
}
}