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

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