I have a JSON that is sent to me as an external service from this url. link I capture these data in my angle as follows: I define my file named Base64.ts that defines the shape of my data
export interface Base64{
"userId":number;
"nombre":string;
"title":string;
"completed": boolean;
}
I capture the data sent from the URL in my about.services.ts
import { Base64 } from "./Base64";
@Injectable({
providedIn: 'root'
})
export class AboutService {
constructor( private httpCliente:HttpClient) {
console.log('servicee esta trabajando');
}
getData2(){
return this.httpCliente.get<Base64[]>('https://jsonplaceholder.typicode.com/todos/1')
}
}
I define the following in my about.component.ts:
import { Component } from '@angular/core';
import { AboutService } from '../about.service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent {
bases =[];
constructor( private data:AboutService){
this.data.getData2().subscribe(dato =>{
this.bases=dato;
})
}
up to this point everything normal. if I did a
console.log(this.bases);
would have the following correct result:
{userId: 1, id: 1, title: "delectus aut autem", completed: false}
THE PROBLEM COMES HERE: I can not access a specific attribute of this data collection. (I want to get the content of "title" and save it in a variable)
I've tried with:
console.log(this.bases[2]);
resulting in console undefined , also probe with:
var variable1 = this.bases.title;
console.log(variable1);
This time I see an error in the command console of Angular
ERROR in src / app / home / home.component.ts (21,33): error TS2339: Property 'title' does not exist on type 'any []'
Thanks in advance