Is there a way to build the mobile nav bar in ng2-bootstrap?

前端 未结 4 1766
逝去的感伤
逝去的感伤 2020-12-08 08:02

I\'ve been implementing ng2-bootstrap and Angular2.

I cannot figure out how to make the mobile navbar open / close.

Is this something that just isn\'

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 08:33

    While Seth's solution works absolutely fine as it is, I modified the collapsing logic. Instead of using the click event, I subscribe to the router events to collapse the menu only after successful navigation.

    export class NavMenuComponent implements OnDestroy {
        public isCollapsed: boolean = true;
        private subscription: Subscription;
    
        constructor(private router: Router) {  
            this.subscription = this.router.events.subscribe(s => {
                if (s instanceof NavigationEnd) {
                    this.isCollapsed = true;
                }
            });
        }
    
        ngOnDestroy() {
            this.subscription.unsubscribe();
        }
    }
    

提交回复
热议问题