Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use @output to fire a boolean from child to parent

Tags:

output

angular

Hi angular community,

I want to fire an Event using @Output to hide or open/close a div containing others components. It's quite simple but I never use EventEmitter before, so i would like when hideDem is called it hide or open/close the div depending on other propreties comming from the child.ts

child.html:

 <img type="button" label="Click" (click)="hideDem()" id="foldup" src="./assets/img/fold_up_blacksmall.png"/>

child.comp.ts:

@Output() open: EventEmitter<any> = new EventEmitter();
@Output() close: EventEmitter<any> = new EventEmitter();

public hideDem(): void {
  this.hideMePartially = !this.hideMePartially;
  if (this.hideMePartially) {
    this.open.emit(true);
  } else {
    this.close.emit(false);
  }
}

parent.comp.html

 <div class="daydetail"> 
<div><my-daydetail [showMePartially]="showVar" ></my-daydetail></div>
  <div [hidden]="(close)=hideDem($event)">
    <div>
       <app-pie-chart [minifiedMe]="hideMeup" ></app-pie-chart>
     </div>
     <div>
       <app-fonctionnaly [minifiedMe]="hideMeup"></app-fonctionnaly>
     </div>
     <div>
       <app-my-verticalchart [minifiedMe]="hideMeup" ></app-my-verticalchart>
     </div>
     <div>
       <app-dysfonction [showMePartially]="hideVar"></app-dysfonction>
     </div>
   </div> <!-- End of hidden-->
</div> <!-- End of daydetail-->
like image 374
Emile Cantero Avatar asked Dec 04 '25 08:12

Emile Cantero


1 Answers

[hidden]="(close)=hideDem($event)"

is invalid markup. (close) can't be inside the expression of another binding.

<my-daydetail [showMePartially]="showVar" 
    (close)="isHidden = true" (open)="isHidden = false"></my-daydetail>
  <div [hidden]="isHidden">
like image 151
Günter Zöchbauer Avatar answered Dec 06 '25 09:12

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!