How can I access a function into child component by event click in parent view.
I have two buttons in my parent view, each one represent a component.
<ul>
<li><button (click)="buttonOne()">component 1</button></li>
<li><button (click)="buttonTwo()">component 2</button></li>
</ul>
and I want to click in button component 1 and show the component 1 and when I click in button component 2 hide the component 1 and show the component 2.
child.component
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'component1',
templateUrl: './componentOne.component.html',
styleUrls: ['./componentOne.component.less']
})
export class ComponentOne implements OnInit {
showComponent: boolean = false;
constructor() {}
buttonOne(): boolean {
this.showComponent = true;
}
buttonTwo(): boolean {
this.showComponent = false;
}
ngOnInit() {}
}
parent.component
import { Component, OnInit } from '@angular/core';
import { ComponentOne } from '...parent-component/component-one.component';
@Component({
selector: 'parent-component',
templateUrl: 'parent-component.component.html',
styleUrls: ['parent-component.component.less']
})
export class ParentComponent implements OnInit {
constructor() {}
ngOnInit() {
}
ngOnDestroy() {
}
}