I am printing an object dateImagen.boolean
and I get an error that the Cannot read property 'boolean' of undefined
, I do console.log(dateImagen)
, but if I get the information that is this:
Object {boolean: true, result: Array(2), mensaje: "Hay imagen"}
but when I print {{dateImagen.boolean}}
I get that message that boolean is undefined and if I print it {{dateImagen}}
if it prints everything coming out like this:
[Object, Object]
I did a JSON.stringify(dateImagen)
and I printed it and I get the object as it is but in string. Do you know if I'm doing something wrong? I'm practicing ionic2 doing a personal project. Thank you very much, this is the code I do:
imagenes.ts
export interface Images{
boolean: boolean,
result: any,
mensaje: string
}
ContentImages.ts
import { Component, Input } from '@angular/core';
import { Images } from '../../app/commons/imagenes';
import { contenidoServices } from '../../app/services/contenidos';
@Component({
selector: 'contenido-images',
templateUrl: 'contenidoImages.html'
})
export class contenidoImage{
dateImagen:Images;
@Input() id: number;
constructor(private contenido: contenidoServices){
}
ngOnInit(){
let idContenido = this.id;
let imagenesContenido = this.contenido.getContenidoImagenes(idContenido);
imagenesContenido.subscribe((res)=>{
let date = {
boolean: (res == 2) ? false : true,
result: res,
mensaje: (res == 2) ? 'No hay imagen' : 'Hay imagen'
}
this.dateImagen = date;
console.log(this.dateImagen);
},(err) => {
console.log(err);
});
}
}
ContentImages.html
<div>
{{dateImagen.boolean}}
</div>