Do you know if you can get the data from the constructor that is obtained from the input component that define an 'id' ?, That is what I do is make a directive <contenido-images [id]="contenido.id"></contenido-images>
that [id]
sent a number that receives it ContentImages.ts and I get it by means of @Input() id
in templateUrl
if I get what I sent to print it so {{id}}
.
But what I want is to get that id from contenidoImages.ts to consult a service and bring more data and then if I print it in templateUrl: 'contenidoImages.html'
, I do a console.log(this.id)
but I get undefined , I do not know why it does not obitiene but if you print it in the template.
I show you how is my code:
page2.ts
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { MenuServices } from '../../app/services/menu';
import { contenidoServices } from '../../app/services/contenidos';
@Component({
selector: 'page-page2',
templateUrl: 'page2.html'
})
export class Page2{
selectedItem: any;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private menu: MenuServices,
private contenido: contenidoServices
){
this.selectedItem = {boolean: true, result: navParams.get('item')};
}
}
page2.html
<div *ngFor="let contenido of selectedItem.result">
{{contenido.id}}
<contenido-images [id]="contenido.id">
</contenido-images>
<div class="contenido-menu">
<h2>{{contenido.titulo}}</h2>
<div class="texto">
{{contenido.texto}}
</div>
</div>
</div>
ContentImages.ts
import { Component, Input } from '@angular/core';
import { contenidoServices } from '../../app/services/contenidos';
@Component({
selector: 'contenido-images',
templateUrl: 'contenidoImages.html'
})
export class contenidoImage{
@Input() id;
constructor(private contenido: contenidoServices){
console.log(this.id);
}
console.log(this.id);
}
ContentImages.html
<ion-slides pager>
<ion-slide>
{{id}}
</ion-slide>
<ion-slide>
{{id}}
</ion-slide>
</ion-slides>