我有两个组件,AppNav 组件和 Machines 组件。AppNav 组件具有工具栏和 sidenav。我还在 AppNav 的工具栏上放置了一个过滤器按钮。在 Machines 组件中有一个 mat-drawer,需要在单击 AppNav 工具栏中的过滤器按钮后进行切换。问题是我不知道如何让两人沟通。Machines 组件不是 AppNav 组件的直接子组件,因为我通过放置在 AppNav 的 sidenav-content 中的路由器插座加载其他组件(机器等)。
从下面看组件:
DrawerService(我想通过创建它来缓解我的挫败感)
import { Injectable } from '@angular/core';
import { MatDrawer } from '@angular/material';
@Injectable({
providedIn: 'root'
})
export class DrawerService {
private drawer: MatDrawer;
/**
* setDrawer
*/
public setDrawer(flyout: MatDrawer) {
this.drawer = flyout;
}
/**
* open
*/
public open() {
return this.drawer.open();
}
/**
* close
*/
public close() {
return this.drawer.close();
}
/**
* toggle …Run Code Online (Sandbox Code Playgroud)