import { Injectable, SkipSelf, Optional } from '@angular/core'; import { Subject, BehaviorSubject } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class FarrisSubMenuService { /* menuItem层级 用于计算paddingLeft */ public level$ = new BehaviorSubject(1); /* submenu展开 */ public open$ = new Subject(); /* 谁的子元素 */ public isChildofSub$ = new Subject(); /* 谁的子元素 */ level = 1; /* Todo paddingLeft使用 */ constructor( @SkipSelf() @Optional() private hostSubmenuService: FarrisSubMenuService, ) { if (this.hostSubmenuService) { this.setLevel(this.hostSubmenuService.level + 1); } } setLevel(value: number) { this.level = value; // this.level$.next(value); } pipeLevel() { this.level$.next(this.level); } }