Property 'results' does not exist on type 'AppComponent'

Viewed 10040

I am trying to get the results field from a json response however I get the error Property 'results' does not exist on type 'AppComponent

import { Component } from '@angular/core';

//in place where you wanted to use `HttpClient`
import { HttpClient } from '@angular/common/http';



@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  title = 'app';

  // Inject HttpClient into your component or service.
  constructor(private http: HttpClient) {}
  ngOnInit(): void {

    // Make the HTTP request:
    this.http.get('assets/api/list.json').subscribe(data => {

      // Read the result field from the JSON response.
      this.results = data['results'];

    });
  }
}
2 Answers

Sometimes ['results'] will log the same error. (maybe for newer angular/ts versions)

 this.http.get(url).subscribe((data:any) => {

  // Read the result field from the JSON response.
  //this.results = data.results;
  this.results = data['results'];
Related