I am trying to pass an id from a div to a child component, this works for me if I use it in the template of the child component, but when I want to use it in the code it appears as undefined
parent component with its respective template
import { Component} from '@angular/core';
import {Tables} from '../single-table-component/single.table.component';
@Component({
selector:'table-component',
templateUrl: 'table.component.html',
styleUrls: ['table.component.css']
})
export class TableComponent{
constructor(
){
}
}
<ngb-panel id="static-1" title="GASTOS REMUNERACIONALES" id="gastoRemuneracionales" #parentInput (click)='0' class="cd col-md-12">
<ng-template ngbPanelContent>
<tables [parentValue]="parentInput.id"></tables>
</ng-template>
</ngb-panel>
the id id="gastoRemuneracionales"
is what I want to pass on to the child through
<tables [parentValue]="parentInput.id"></tables>
child component code
import {Component, Input} from '@angular/core';
import {AngularFireDatabase, FirebaseListObservable} from 'angularfire2/database';
import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/ng-bootstrap';
import {TableComponent} from '../table-component/table.component';
@Component({
selector: 'tables',
templateUrl: './single.table.component.html',
inputs: ['parentValue']
})
export class Tables{
closeResult: string;
title:string = 'hola mundo';
datos: FirebaseListObservable<any[]>;
public parentValue:string;
constructor(private modalService: NgbModal, private af : AngularFireDatabase) {
console.log(this.parentValue+ this.title)
this.af.list('/subvencionEscolar/'+ this.parentValue);
}
}
<table class="table table-striped tb col-md-12">
<thead>
<th>N°</th>
<th>Nombre</th>
<th>Detalles</th>
<th>Total</th>
<th>{{parentValue}}</th>
</thead>
<tbody>
<tr *ngFor="let mocks of datos | async">
<th>{{mocks.id}}</th>
<th> {{mocks.name}} </th>
<td> <button class="btn btn-lg btn-outline-primary">Launch demo modal</button>
</td>
<td>{{mocks.detail.montodoc}}</td>
</tr>
</tbody>
</table>
<th>{{parentValue}}</th>
but in the code it shows me undefined
constructor(private modalService: NgbModal, private af : AngularFireDatabase) {
console.log(this.parentValue+ this.title)
this.af.list('/subvencionEscolar/'+ this.parentValue);
}
the console log shows me "undefinedhola mundo" where the hello world is this.title
: c
I am new at angular, and I have searched everywhere, always arriving at the same result, in advance thanks for your help