You can use EventEmitter .
header.html application
<div> <button (click)="emitClick()"></button> </div>
application header.ts
@Output() _clickEvent:EventEmitter<any>=new EventEmitter(); constructor(){ } ngOnInit(){ } emitClick($event){ this.clickEvent.emit() }
application-component.html
<div class="off-canvas" [ngClass]="{'someClassName':active}"> <app-header (_clickEvent)="toggleActive($event)"><app-header> <app-home></app-home> <app-footer></app-footer> </div>
app-component.ts
active:boolean=false; constructor(){ } ngOnInit(){ } toggleActive($event){
You must declare the active variable in your app-component.ts and initialize it before Boolean. Each click will cause an active switch between true and false. A class named "someClassName" will be added by ngClass whenever the it true variable is active.
source share