【发布时间】:2016-08-13 23:03:47
【问题描述】:
假设我有两个组件:主页和编辑器。
在主页组件,当我点击“添加帖子”按钮时,我会显示editor组件。
首页组件的视图
<button (click)="showEditor()">Show editor</button>
<editorComponent *ngIf="clicked"></editorComponent>
showEditor() 只需将clicked 变量设置为true,然后editor 组件就会出现。
编辑器组件的视图
<div class="editor">
...some editor stuff
<button (click)="cancel()">Cancel</button>
</div>
单击Cancel 按钮时,我想将editor 组件隐藏在homepage 组件中。为此,我应该再次将 homepageComponent.clicked 设置为 false,但如何在另一个组件中执行此操作。你有更好的主意吗?
【问题讨论】:
标签: javascript angular typescript components