Angular 2 material : sidenav toggle from component

前端 未结 4 1738
挽巷
挽巷 2021-02-04 05:28

I\'m using Angular 2 Material sidenav in my project this way:


  
      

        
4条回答
  •  清酒与你
    2021-02-04 06:07

    You want to declare a ViewChild in your controller that references the MdSidenav inside your component, like this:

    // Sidemenu
    @ViewChild('start') sidenav: MdSidenav;
    

    where start is the name of the component you want to reference, in this case the sidenav.

    Next you can call methods on that sidenav, like this.sidenav.toggle() inside your controller's functions.

    https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#parent-to-view-child

提交回复
热议问题