How to listen events from child template inside a child component when they are called from parent template?
I have 2 components: app.ts and child.ts;
app.ts:
@Component({
selector: 'app',
template: '<button>Main button</buton><router-outlet></router-outlet>',
encapsulation: ViewEncapsulation.None,
directives: [ROUTER_DIRECTIVES],
})
@RouteConfig([
{path: '/child/', component: ChildCmp, as: 'Child'}
])
export class AppCmp {
}
child.ts:
@Component({
selector: 'child',
template: 'This is child page!'
})
export class AppCmp {
// This method should be called, when mail button is pressed
onChange() {
}
}
I don't want to add click event to button, instead I would like to add some kind of listener for onChange function in child component so it listens when button in parent view is clicked. I've tried with HostListener, but it only triggers, when HostListener is added to parent component.