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

不羁岁月 提交于 2019-12-07 16:41:08

问题


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-->

回答1:


[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">


来源:https://stackoverflow.com/questions/45323052/how-to-use-output-to-fire-a-boolean-from-child-to-parent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!