I am trying to access #temp of modalconfirm.component.html in parent app.component.ts but its always null.
modalconfirm.component.html
<button type="button" class="btn btn-primary" (click)="openModal(template)">Open modal</button>
<br><br>
<pre class="card card-block card-header">{{message}}</pre>
<ng-template #template>
<div class="modal-body text-center">
<p>Do you want to confirm?</p>
<button type="button" class="btn btn-default" (click)="confirm()" >Yes</button>
<button type="button" class="btn btn-primary" (click)="decline()" >No</button>
</div>
</ng-template>
app.component.ts
import { Component, TemplateRef, ViewChild, ElementRef } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { BsModalService } from 'ngx-bootstrap/modal';
import { ModalcomfirmComponent } from './modalcomfirm/modalcomfirm.component';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
template:`
<modalcomfirm ></modalcomfirm>
<table>
<tr><td><div (click)="TestChild()">1</div></td></tr>
<tr><td><div>2</div></td></tr>
`
// styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
@ViewChild("template") inputChild: ElementRef;
@ViewChild(ModalcomfirmComponent ) child: ModalcomfirmComponent;
TestChild(){
console.log(this.inputChild); //undefined
}
ngOnInit(){
}
confirmParent(evt) {
console.log(evt);
}
}