| 12345678910111213141516171819202122232425262728293031 |
- import { Component, OnInit, Input, ViewChild } from '@angular/core';
- import { SidenavService } from '../sidenav.service';
- import { startWith, map } from "rxjs/operators";
-
- @Component({
- selector: 'sidenav-drawer-item',
- templateUrl: './sidenav-drawer-item.component.html',
- styleUrls: ['./sidenav-drawer-item.component.css']
- })
- export class SidenavDrawerItemComponent implements OnInit {
- @Input('route') route;
- @Input('itemTitle') title;
- @Input('check') check?;
-
- @ViewChild('button', { static: true }) element;
-
- constructor(
- public _menu: SidenavService
- ){ }
-
- ngOnInit(){
- if(this.check)
- this._menu.currentRouteChange.pipe(
- startWith(this._menu.currentRoute),
- map(url => url)
- ).subscribe((url) => {
- const _regex = new RegExp(this.check)
- if(_regex.exec(url)) this._menu.setSelectedItem(this.element.nativeElement)
- })
- }
- }
|