angular父组件通过@ViewChild 主动获取子组 件的数据和方法

时间:2019-05-21 16:37:46   收藏:0   阅读:324

1.调用子组件给子组件定义一个名称

<app-footer #footerChild></app-footer>

2. 引入 ViewChild

import { Component, OnInit ,ViewChild} from ‘@angular/core‘;

3. ViewChild 和刚才的子组件关联起来

 

 @ViewChild(‘footerChild‘) footer;

4.调用子组件

run(){ 
    this.footer.footerRun();
}

非父子组件通讯

 

1、公共的服务 2、Localstorage (推荐) 3、Cookie

 

 

 

 

原文:https://www.cnblogs.com/loaderman/p/10900441.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!