Error: Property 'data' does not exist on type 'Entidad[ ]'


#1

Hi, I have an error with my app, I want to show the name of Entidades, I don’t know what’s wrong!

I hope someone help me!

Thanks.

models/entidad.ts

export interface Entidad {
idEntidad: number,
nombre: string;
activo: number,
data: string;
}

providers/arme-tools

import { Injectable } from ‘@angular/core’;
import { Http } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;
import { Observable } from ‘rxjs/Rx’;
import {Entidad} from ‘…/models/entidad’;

/*
Generated class for the ArmeTools provider.

See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class ArmeTools {
armeApiUrl = ‘http://192.168.0.26:3000’;

constructor(public http: Http) {
console.log(‘Hello ArmeTools Provider’);
}
entidad(): Observable<Entidad[]>{
return this.http.get(${this.armeApiUrl}/entidades).map(res => <Entidad[]>res.json());
}

}

home.html

ion-content padding

ion-list
button ion-item *ngFor=“let cate of cates”
{{cate.nombre}}
button
ion-list

ion-content

home.ts

import { Component } from ‘@angular/core’;

import { NavController } from ‘ionic-angular’;
import { ArmeTools } from ‘…/…/providers/arme-tools’;
import { Entidad } from ‘…/…/models/entidad’;

@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {
cates : Entidad[]

constructor(public navCtrl: NavController,private armetools: ArmeTools) {
armetools.entidad().subscribe(cates => {
console.log(cates);
this.cates = cates.data;
})
}

}

ERROR

ionic $ [13:33:30] transpile update started …
[13:33:39] typescript: src/pages/home/home.ts, line: 17
Property ‘data’ does not exist on type ‘Entidad[]’.

  L16:  console.log(cates);
  L17:  this.cates = cates.data;

[13:33:39] transpile update failed
[13:33:39] watch ready


#2

It’s been quite a while, but how did you solved this issue, I’m experiencing a similar problem?