[英]In Angular, how do I run a method in a different component than the current component
如何在 Angular 中的組件 X 中運行組件 Y 中的方法。
X 組件中的方法
onClear() {
this.editor.clear();
// environment.templateId=0;
this.openScheduler();
}
像這樣的Y分量
X.onclear();
使用服務在組件之間進行交互或使用共享方法。
如果它是父子組件關系,您可以這樣做。
@ViewChild('componentName', { static: false })
component: SomeComponent;
在模板中:
<component #componentName></component>
比你可以:
onClear() {
this.editor.clear();
// environment.templateId=0;
this.component.doSomehting();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.