parent-component.component.ts
@Component({
selector: 'app-parent-component',
templateUrl: './parent-component.component.html',
})
export class ParentComponentComponent {
someFunction() {
childComponent.someChildFunction()
}
}
parent-component.component.html
<ngTemplate>
<app-child-component></app-child-component>
</ngTemplate>
child-component.component.ts
@Component({
selector: 'app-child-component',
templateUrl: './child-component.component.html',
})
export class ChildComponentComponent {
someChildFunction() {
//some usefull work
}
}
child-component.component.html
<input [(ngmodel)]="search">
How to call the child function from the parent that is within the ngTemplate
i tried to it using the component reference.
@ViewChild(ChildComponentComponent)
private childComponent: ChildComponentComponent;
but was undefined.. then tried
<ng-container *ngTemplateOutlet="template"></ng-container>
in parent component
That time any update inside the child component is not reflecting like an input with ngModel.
Any help would be helpful. Or some better solution would also work..