简体   繁体   English

如何从Angular 2中的父组件触发子组件中的本地引用

[英]How to trigger local reference in child component from parent component in Angular 2

In scenario when I have在我有的情况下

parent component:父组件:

  <button (click)="panel.toggle($event)">Click</div>

child:孩子:

   <child></child> which has the reference

     and includes

     <p-overlayPanel  #panel>
       Content
    </p-overlayPanel>

How can I access #panel reference from parent component?如何从父组件访问#panel 引用? PrimeNG overlay panel PrimeNG 覆盖面板

 @ViewChild(‘panel’) panel: ParentComponent

使用@ViewChild()装饰器,您可以从父组件访问子组件

You can toggle: this.panel.show();您可以切换: this.panel.show(); this.panel.hide(); this.panel.hide();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Angular 2中的子组件事件触发父组件中的本地引用? - How to trigger local reference in parent component from child component event in Angular 2? 如何从父组件OnSubmit Angular 4触发子组件的验证? - how to trigger a validation of child component from parent component OnSubmit Angular 4? 如何从 angular 中的父组件触发子组件的 function? - How to trigger a function of child component from parent in angular? 父组件中的触发事件来自路由Angular中子组件的加载 - Trigger event in Parent component from child component load in routing Angular 如何使用模板表单从Angular 2的父组件中触发子组件验证器 - How to trigger child component validators from parent component in Angular 2 using template forms 如何从angular2的子组件访问父组件的视图引用 - How to access view reference of parent component from child component in angular2 从父组件到子组件Angular2 / 4触发悬停样式 - Trigger hover style from parent to child component Angular2/4 如何从父组件重置子组件中的字段 - 角度 - How to reset a field in child component from parent component - angular 如何从 Angular 9 中的子组件访问父组件 - How to Access Parent Component from Child Component in Angular 9 在Angular 1.5中,如何从子组件中编译父组件的html? - In Angular 1.5, how to compile the html of a parent component from a child component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM