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