Closing side-nav on clicking router link for small devices












1















I am using side-nav component in my project for routing between the components,which looks like this:



enter image description here



Here i am facing an issue.The side-nav appears as toggle-menu for mobile devices as shown in the image. When i click/select any list-item (ex Home) .The side-nav should close.But it is not.




I have asked it once, still no appropriate solution.




Here is the stackblitz DEMO










share|improve this question





























    1















    I am using side-nav component in my project for routing between the components,which looks like this:



    enter image description here



    Here i am facing an issue.The side-nav appears as toggle-menu for mobile devices as shown in the image. When i click/select any list-item (ex Home) .The side-nav should close.But it is not.




    I have asked it once, still no appropriate solution.




    Here is the stackblitz DEMO










    share|improve this question



























      1












      1








      1


      1






      I am using side-nav component in my project for routing between the components,which looks like this:



      enter image description here



      Here i am facing an issue.The side-nav appears as toggle-menu for mobile devices as shown in the image. When i click/select any list-item (ex Home) .The side-nav should close.But it is not.




      I have asked it once, still no appropriate solution.




      Here is the stackblitz DEMO










      share|improve this question
















      I am using side-nav component in my project for routing between the components,which looks like this:



      enter image description here



      Here i am facing an issue.The side-nav appears as toggle-menu for mobile devices as shown in the image. When i click/select any list-item (ex Home) .The side-nav should close.But it is not.




      I have asked it once, still no appropriate solution.




      Here is the stackblitz DEMO







      angular angular-material angular6 angular-routing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 7:15







      Empty_Soul

















      asked Nov 28 '18 at 5:18









      Empty_SoulEmpty_Soul

      36012




      36012
























          3 Answers
          3






          active

          oldest

          votes


















          1














          You can do this by




          • providing a reference to mat-sidenav as <mat-sidenav #snav

          • Using this reference to toggle or close the mat-sidenav, from where you want this side nav to close. Say, from an anchor click as
            <a mat-list-item routerLink="." *ngFor="let nav of fillerNav" (click)="snav.toggle()" >

          • You can use (click)="snav.toggle()" or (click)="snav.close()"


          Code :



          <mat-sidenav #snav [mode]="mobileQuery.matches ? 'over' : 'side'" 
          [fixedInViewport]="mobileQuery.matches" fixedTopGap="56">
          <mat-nav-list>
          <a mat-list-item routerLink="." *ngFor="let nav of fillerNav"
          (click)="snav.toggle()" >{{nav}}</a>
          </mat-nav-list>
          </mat-sidenav>


          Stackblitz Demo showing closing of side nav on clicking on item-link



          Application Code : https://stackblitz.com/edit/angular-close-side-nav-on-button-click?file=app%2Fsidenav-responsive-example.html




          Update 1 :





          • Side Nav will close only in mobile mode, and not in desktop mode.



            Code attached in Question








          share|improve this answer


























          • Let me try your answer.

            – Empty_Soul
            Nov 28 '18 at 7:11











          • In your code the toggle-menu (i,e side-nav) is already present for larger screens also. I want to make toggle-menu only for small devices.

            – Empty_Soul
            Nov 28 '18 at 7:15











          • i just took a small demo from the stackblitz and implemented the close functionlaity for the sidenav.

            – Abhishek Kumar
            Nov 28 '18 at 7:16






          • 1





            I have already asked this question twice still i didn't got any solution...:)

            – Empty_Soul
            Nov 28 '18 at 7:17






          • 1





            @Empty_Soul see the updated answer according to your stackblitz. Now closing in mobile mode only.

            – Abhishek Kumar
            Nov 28 '18 at 7:33



















          0














          Not the best solution but consider this:



              <mat-sidenav-container class="sidenav-container">
          <mat-sidenav #drawer fixedInViewport="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
          [mode]="(isHandset$ | async) ? 'over' : 'side'" [opened]="!(isHandset$ | async)">
          <mat-toolbar color="primary" style="margin-top:30px;"> Business</mat-toolbar>

          <mat-nav-list >
          <mat-list-item (click)="select('home')" >
          <mat-icon matListIcon>home</mat-icon>
          <span matLine>Home</span>
          </mat-list-item>

          <mat-list-item (click)="select('person')" >
          <mat-icon matListIcon>person</mat-icon>
          <span matLine>Customers</span>
          </mat-list-item>

          <mat-list-item (click)="select('employees')" >
          <mat-icon matListIcon>group_work</mat-icon>
          <span matLine>employees</span>
          </mat-list-item>

          <mat-list-item (click)="select('business')">
          <mat-icon matListIcon>business</mat-icon>
          <span matLine>Business</span>
          </mat-list-item>

          </mat-nav-list>
          </mat-sidenav>

          <mat-sidenav-content>
          <mat-toolbar color="primary">
          <button type="button" aria-label="Toggle sidenav" mat-icon-button (click)="drawer.toggle()" *ngIf="isHandset$ | async">
          <mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
          </button>

          </mat-toolbar>

          <div class="ylb-app-content">
          <ng-content></ng-content>
          </div>
          </mat-sidenav-content>
          </mat-sidenav-container>


          and in the ts add a function like:



          select(option: string) {
          // handle it
          this.viewChild.toggle();
          }





          share|improve this answer


























          • Sorry it didn't worked for me.

            – Empty_Soul
            Nov 28 '18 at 6:39











          • What did it say or do?

            – quijote
            Dec 5 '18 at 20:49



















          0














          In your Demo,
          I added following content in component.ts file and it is working fine.
          I took reference of element in ts file and called toggle method.
          Please try this and let me know if it is working fine or not.



          export class SidenavResponsiveExample {
          @ViewChild('drawer') drawer;

          selected(option: string) {
          this.drawer.toggle();
          }
          }


          Demo: https://stackblitz.com/edit/angular-5ll5i7-a6je6c






          share|improve this answer
























          • Onclick the list-item for ex home. The side-nav is hiding fine. but i want to hide it only for small devices.

            – Empty_Soul
            Nov 28 '18 at 7:34











          • Do you want to keep it open for small devices ? or you do not want to open the menu itself for small devices ?

            – Vikram kumar Chhajer
            Nov 29 '18 at 7:19











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53512602%2fclosing-side-nav-on-clicking-router-link-for-small-devices%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can do this by




          • providing a reference to mat-sidenav as <mat-sidenav #snav

          • Using this reference to toggle or close the mat-sidenav, from where you want this side nav to close. Say, from an anchor click as
            <a mat-list-item routerLink="." *ngFor="let nav of fillerNav" (click)="snav.toggle()" >

          • You can use (click)="snav.toggle()" or (click)="snav.close()"


          Code :



          <mat-sidenav #snav [mode]="mobileQuery.matches ? 'over' : 'side'" 
          [fixedInViewport]="mobileQuery.matches" fixedTopGap="56">
          <mat-nav-list>
          <a mat-list-item routerLink="." *ngFor="let nav of fillerNav"
          (click)="snav.toggle()" >{{nav}}</a>
          </mat-nav-list>
          </mat-sidenav>


          Stackblitz Demo showing closing of side nav on clicking on item-link



          Application Code : https://stackblitz.com/edit/angular-close-side-nav-on-button-click?file=app%2Fsidenav-responsive-example.html




          Update 1 :





          • Side Nav will close only in mobile mode, and not in desktop mode.



            Code attached in Question








          share|improve this answer


























          • Let me try your answer.

            – Empty_Soul
            Nov 28 '18 at 7:11











          • In your code the toggle-menu (i,e side-nav) is already present for larger screens also. I want to make toggle-menu only for small devices.

            – Empty_Soul
            Nov 28 '18 at 7:15











          • i just took a small demo from the stackblitz and implemented the close functionlaity for the sidenav.

            – Abhishek Kumar
            Nov 28 '18 at 7:16






          • 1





            I have already asked this question twice still i didn't got any solution...:)

            – Empty_Soul
            Nov 28 '18 at 7:17






          • 1





            @Empty_Soul see the updated answer according to your stackblitz. Now closing in mobile mode only.

            – Abhishek Kumar
            Nov 28 '18 at 7:33
















          1














          You can do this by




          • providing a reference to mat-sidenav as <mat-sidenav #snav

          • Using this reference to toggle or close the mat-sidenav, from where you want this side nav to close. Say, from an anchor click as
            <a mat-list-item routerLink="." *ngFor="let nav of fillerNav" (click)="snav.toggle()" >

          • You can use (click)="snav.toggle()" or (click)="snav.close()"


          Code :



          <mat-sidenav #snav [mode]="mobileQuery.matches ? 'over' : 'side'" 
          [fixedInViewport]="mobileQuery.matches" fixedTopGap="56">
          <mat-nav-list>
          <a mat-list-item routerLink="." *ngFor="let nav of fillerNav"
          (click)="snav.toggle()" >{{nav}}</a>
          </mat-nav-list>
          </mat-sidenav>


          Stackblitz Demo showing closing of side nav on clicking on item-link



          Application Code : https://stackblitz.com/edit/angular-close-side-nav-on-button-click?file=app%2Fsidenav-responsive-example.html




          Update 1 :





          • Side Nav will close only in mobile mode, and not in desktop mode.



            Code attached in Question








          share|improve this answer


























          • Let me try your answer.

            – Empty_Soul
            Nov 28 '18 at 7:11











          • In your code the toggle-menu (i,e side-nav) is already present for larger screens also. I want to make toggle-menu only for small devices.

            – Empty_Soul
            Nov 28 '18 at 7:15











          • i just took a small demo from the stackblitz and implemented the close functionlaity for the sidenav.

            – Abhishek Kumar
            Nov 28 '18 at 7:16






          • 1





            I have already asked this question twice still i didn't got any solution...:)

            – Empty_Soul
            Nov 28 '18 at 7:17






          • 1





            @Empty_Soul see the updated answer according to your stackblitz. Now closing in mobile mode only.

            – Abhishek Kumar
            Nov 28 '18 at 7:33














          1












          1








          1







          You can do this by




          • providing a reference to mat-sidenav as <mat-sidenav #snav

          • Using this reference to toggle or close the mat-sidenav, from where you want this side nav to close. Say, from an anchor click as
            <a mat-list-item routerLink="." *ngFor="let nav of fillerNav" (click)="snav.toggle()" >

          • You can use (click)="snav.toggle()" or (click)="snav.close()"


          Code :



          <mat-sidenav #snav [mode]="mobileQuery.matches ? 'over' : 'side'" 
          [fixedInViewport]="mobileQuery.matches" fixedTopGap="56">
          <mat-nav-list>
          <a mat-list-item routerLink="." *ngFor="let nav of fillerNav"
          (click)="snav.toggle()" >{{nav}}</a>
          </mat-nav-list>
          </mat-sidenav>


          Stackblitz Demo showing closing of side nav on clicking on item-link



          Application Code : https://stackblitz.com/edit/angular-close-side-nav-on-button-click?file=app%2Fsidenav-responsive-example.html




          Update 1 :





          • Side Nav will close only in mobile mode, and not in desktop mode.



            Code attached in Question








          share|improve this answer















          You can do this by




          • providing a reference to mat-sidenav as <mat-sidenav #snav

          • Using this reference to toggle or close the mat-sidenav, from where you want this side nav to close. Say, from an anchor click as
            <a mat-list-item routerLink="." *ngFor="let nav of fillerNav" (click)="snav.toggle()" >

          • You can use (click)="snav.toggle()" or (click)="snav.close()"


          Code :



          <mat-sidenav #snav [mode]="mobileQuery.matches ? 'over' : 'side'" 
          [fixedInViewport]="mobileQuery.matches" fixedTopGap="56">
          <mat-nav-list>
          <a mat-list-item routerLink="." *ngFor="let nav of fillerNav"
          (click)="snav.toggle()" >{{nav}}</a>
          </mat-nav-list>
          </mat-sidenav>


          Stackblitz Demo showing closing of side nav on clicking on item-link



          Application Code : https://stackblitz.com/edit/angular-close-side-nav-on-button-click?file=app%2Fsidenav-responsive-example.html




          Update 1 :





          • Side Nav will close only in mobile mode, and not in desktop mode.



            Code attached in Question









          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 28 '18 at 7:32

























          answered Nov 28 '18 at 7:10









          Abhishek KumarAbhishek Kumar

          1,175417




          1,175417













          • Let me try your answer.

            – Empty_Soul
            Nov 28 '18 at 7:11











          • In your code the toggle-menu (i,e side-nav) is already present for larger screens also. I want to make toggle-menu only for small devices.

            – Empty_Soul
            Nov 28 '18 at 7:15











          • i just took a small demo from the stackblitz and implemented the close functionlaity for the sidenav.

            – Abhishek Kumar
            Nov 28 '18 at 7:16






          • 1





            I have already asked this question twice still i didn't got any solution...:)

            – Empty_Soul
            Nov 28 '18 at 7:17






          • 1





            @Empty_Soul see the updated answer according to your stackblitz. Now closing in mobile mode only.

            – Abhishek Kumar
            Nov 28 '18 at 7:33



















          • Let me try your answer.

            – Empty_Soul
            Nov 28 '18 at 7:11











          • In your code the toggle-menu (i,e side-nav) is already present for larger screens also. I want to make toggle-menu only for small devices.

            – Empty_Soul
            Nov 28 '18 at 7:15











          • i just took a small demo from the stackblitz and implemented the close functionlaity for the sidenav.

            – Abhishek Kumar
            Nov 28 '18 at 7:16






          • 1





            I have already asked this question twice still i didn't got any solution...:)

            – Empty_Soul
            Nov 28 '18 at 7:17






          • 1





            @Empty_Soul see the updated answer according to your stackblitz. Now closing in mobile mode only.

            – Abhishek Kumar
            Nov 28 '18 at 7:33

















          Let me try your answer.

          – Empty_Soul
          Nov 28 '18 at 7:11





          Let me try your answer.

          – Empty_Soul
          Nov 28 '18 at 7:11













          In your code the toggle-menu (i,e side-nav) is already present for larger screens also. I want to make toggle-menu only for small devices.

          – Empty_Soul
          Nov 28 '18 at 7:15





          In your code the toggle-menu (i,e side-nav) is already present for larger screens also. I want to make toggle-menu only for small devices.

          – Empty_Soul
          Nov 28 '18 at 7:15













          i just took a small demo from the stackblitz and implemented the close functionlaity for the sidenav.

          – Abhishek Kumar
          Nov 28 '18 at 7:16





          i just took a small demo from the stackblitz and implemented the close functionlaity for the sidenav.

          – Abhishek Kumar
          Nov 28 '18 at 7:16




          1




          1





          I have already asked this question twice still i didn't got any solution...:)

          – Empty_Soul
          Nov 28 '18 at 7:17





          I have already asked this question twice still i didn't got any solution...:)

          – Empty_Soul
          Nov 28 '18 at 7:17




          1




          1





          @Empty_Soul see the updated answer according to your stackblitz. Now closing in mobile mode only.

          – Abhishek Kumar
          Nov 28 '18 at 7:33





          @Empty_Soul see the updated answer according to your stackblitz. Now closing in mobile mode only.

          – Abhishek Kumar
          Nov 28 '18 at 7:33













          0














          Not the best solution but consider this:



              <mat-sidenav-container class="sidenav-container">
          <mat-sidenav #drawer fixedInViewport="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
          [mode]="(isHandset$ | async) ? 'over' : 'side'" [opened]="!(isHandset$ | async)">
          <mat-toolbar color="primary" style="margin-top:30px;"> Business</mat-toolbar>

          <mat-nav-list >
          <mat-list-item (click)="select('home')" >
          <mat-icon matListIcon>home</mat-icon>
          <span matLine>Home</span>
          </mat-list-item>

          <mat-list-item (click)="select('person')" >
          <mat-icon matListIcon>person</mat-icon>
          <span matLine>Customers</span>
          </mat-list-item>

          <mat-list-item (click)="select('employees')" >
          <mat-icon matListIcon>group_work</mat-icon>
          <span matLine>employees</span>
          </mat-list-item>

          <mat-list-item (click)="select('business')">
          <mat-icon matListIcon>business</mat-icon>
          <span matLine>Business</span>
          </mat-list-item>

          </mat-nav-list>
          </mat-sidenav>

          <mat-sidenav-content>
          <mat-toolbar color="primary">
          <button type="button" aria-label="Toggle sidenav" mat-icon-button (click)="drawer.toggle()" *ngIf="isHandset$ | async">
          <mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
          </button>

          </mat-toolbar>

          <div class="ylb-app-content">
          <ng-content></ng-content>
          </div>
          </mat-sidenav-content>
          </mat-sidenav-container>


          and in the ts add a function like:



          select(option: string) {
          // handle it
          this.viewChild.toggle();
          }





          share|improve this answer


























          • Sorry it didn't worked for me.

            – Empty_Soul
            Nov 28 '18 at 6:39











          • What did it say or do?

            – quijote
            Dec 5 '18 at 20:49
















          0














          Not the best solution but consider this:



              <mat-sidenav-container class="sidenav-container">
          <mat-sidenav #drawer fixedInViewport="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
          [mode]="(isHandset$ | async) ? 'over' : 'side'" [opened]="!(isHandset$ | async)">
          <mat-toolbar color="primary" style="margin-top:30px;"> Business</mat-toolbar>

          <mat-nav-list >
          <mat-list-item (click)="select('home')" >
          <mat-icon matListIcon>home</mat-icon>
          <span matLine>Home</span>
          </mat-list-item>

          <mat-list-item (click)="select('person')" >
          <mat-icon matListIcon>person</mat-icon>
          <span matLine>Customers</span>
          </mat-list-item>

          <mat-list-item (click)="select('employees')" >
          <mat-icon matListIcon>group_work</mat-icon>
          <span matLine>employees</span>
          </mat-list-item>

          <mat-list-item (click)="select('business')">
          <mat-icon matListIcon>business</mat-icon>
          <span matLine>Business</span>
          </mat-list-item>

          </mat-nav-list>
          </mat-sidenav>

          <mat-sidenav-content>
          <mat-toolbar color="primary">
          <button type="button" aria-label="Toggle sidenav" mat-icon-button (click)="drawer.toggle()" *ngIf="isHandset$ | async">
          <mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
          </button>

          </mat-toolbar>

          <div class="ylb-app-content">
          <ng-content></ng-content>
          </div>
          </mat-sidenav-content>
          </mat-sidenav-container>


          and in the ts add a function like:



          select(option: string) {
          // handle it
          this.viewChild.toggle();
          }





          share|improve this answer


























          • Sorry it didn't worked for me.

            – Empty_Soul
            Nov 28 '18 at 6:39











          • What did it say or do?

            – quijote
            Dec 5 '18 at 20:49














          0












          0








          0







          Not the best solution but consider this:



              <mat-sidenav-container class="sidenav-container">
          <mat-sidenav #drawer fixedInViewport="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
          [mode]="(isHandset$ | async) ? 'over' : 'side'" [opened]="!(isHandset$ | async)">
          <mat-toolbar color="primary" style="margin-top:30px;"> Business</mat-toolbar>

          <mat-nav-list >
          <mat-list-item (click)="select('home')" >
          <mat-icon matListIcon>home</mat-icon>
          <span matLine>Home</span>
          </mat-list-item>

          <mat-list-item (click)="select('person')" >
          <mat-icon matListIcon>person</mat-icon>
          <span matLine>Customers</span>
          </mat-list-item>

          <mat-list-item (click)="select('employees')" >
          <mat-icon matListIcon>group_work</mat-icon>
          <span matLine>employees</span>
          </mat-list-item>

          <mat-list-item (click)="select('business')">
          <mat-icon matListIcon>business</mat-icon>
          <span matLine>Business</span>
          </mat-list-item>

          </mat-nav-list>
          </mat-sidenav>

          <mat-sidenav-content>
          <mat-toolbar color="primary">
          <button type="button" aria-label="Toggle sidenav" mat-icon-button (click)="drawer.toggle()" *ngIf="isHandset$ | async">
          <mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
          </button>

          </mat-toolbar>

          <div class="ylb-app-content">
          <ng-content></ng-content>
          </div>
          </mat-sidenav-content>
          </mat-sidenav-container>


          and in the ts add a function like:



          select(option: string) {
          // handle it
          this.viewChild.toggle();
          }





          share|improve this answer















          Not the best solution but consider this:



              <mat-sidenav-container class="sidenav-container">
          <mat-sidenav #drawer fixedInViewport="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
          [mode]="(isHandset$ | async) ? 'over' : 'side'" [opened]="!(isHandset$ | async)">
          <mat-toolbar color="primary" style="margin-top:30px;"> Business</mat-toolbar>

          <mat-nav-list >
          <mat-list-item (click)="select('home')" >
          <mat-icon matListIcon>home</mat-icon>
          <span matLine>Home</span>
          </mat-list-item>

          <mat-list-item (click)="select('person')" >
          <mat-icon matListIcon>person</mat-icon>
          <span matLine>Customers</span>
          </mat-list-item>

          <mat-list-item (click)="select('employees')" >
          <mat-icon matListIcon>group_work</mat-icon>
          <span matLine>employees</span>
          </mat-list-item>

          <mat-list-item (click)="select('business')">
          <mat-icon matListIcon>business</mat-icon>
          <span matLine>Business</span>
          </mat-list-item>

          </mat-nav-list>
          </mat-sidenav>

          <mat-sidenav-content>
          <mat-toolbar color="primary">
          <button type="button" aria-label="Toggle sidenav" mat-icon-button (click)="drawer.toggle()" *ngIf="isHandset$ | async">
          <mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
          </button>

          </mat-toolbar>

          <div class="ylb-app-content">
          <ng-content></ng-content>
          </div>
          </mat-sidenav-content>
          </mat-sidenav-container>


          and in the ts add a function like:



          select(option: string) {
          // handle it
          this.viewChild.toggle();
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 28 '18 at 7:20









          Dusan Radovanovic

          568314




          568314










          answered Nov 28 '18 at 6:16









          quijotequijote

          177




          177













          • Sorry it didn't worked for me.

            – Empty_Soul
            Nov 28 '18 at 6:39











          • What did it say or do?

            – quijote
            Dec 5 '18 at 20:49



















          • Sorry it didn't worked for me.

            – Empty_Soul
            Nov 28 '18 at 6:39











          • What did it say or do?

            – quijote
            Dec 5 '18 at 20:49

















          Sorry it didn't worked for me.

          – Empty_Soul
          Nov 28 '18 at 6:39





          Sorry it didn't worked for me.

          – Empty_Soul
          Nov 28 '18 at 6:39













          What did it say or do?

          – quijote
          Dec 5 '18 at 20:49





          What did it say or do?

          – quijote
          Dec 5 '18 at 20:49











          0














          In your Demo,
          I added following content in component.ts file and it is working fine.
          I took reference of element in ts file and called toggle method.
          Please try this and let me know if it is working fine or not.



          export class SidenavResponsiveExample {
          @ViewChild('drawer') drawer;

          selected(option: string) {
          this.drawer.toggle();
          }
          }


          Demo: https://stackblitz.com/edit/angular-5ll5i7-a6je6c






          share|improve this answer
























          • Onclick the list-item for ex home. The side-nav is hiding fine. but i want to hide it only for small devices.

            – Empty_Soul
            Nov 28 '18 at 7:34











          • Do you want to keep it open for small devices ? or you do not want to open the menu itself for small devices ?

            – Vikram kumar Chhajer
            Nov 29 '18 at 7:19
















          0














          In your Demo,
          I added following content in component.ts file and it is working fine.
          I took reference of element in ts file and called toggle method.
          Please try this and let me know if it is working fine or not.



          export class SidenavResponsiveExample {
          @ViewChild('drawer') drawer;

          selected(option: string) {
          this.drawer.toggle();
          }
          }


          Demo: https://stackblitz.com/edit/angular-5ll5i7-a6je6c






          share|improve this answer
























          • Onclick the list-item for ex home. The side-nav is hiding fine. but i want to hide it only for small devices.

            – Empty_Soul
            Nov 28 '18 at 7:34











          • Do you want to keep it open for small devices ? or you do not want to open the menu itself for small devices ?

            – Vikram kumar Chhajer
            Nov 29 '18 at 7:19














          0












          0








          0







          In your Demo,
          I added following content in component.ts file and it is working fine.
          I took reference of element in ts file and called toggle method.
          Please try this and let me know if it is working fine or not.



          export class SidenavResponsiveExample {
          @ViewChild('drawer') drawer;

          selected(option: string) {
          this.drawer.toggle();
          }
          }


          Demo: https://stackblitz.com/edit/angular-5ll5i7-a6je6c






          share|improve this answer













          In your Demo,
          I added following content in component.ts file and it is working fine.
          I took reference of element in ts file and called toggle method.
          Please try this and let me know if it is working fine or not.



          export class SidenavResponsiveExample {
          @ViewChild('drawer') drawer;

          selected(option: string) {
          this.drawer.toggle();
          }
          }


          Demo: https://stackblitz.com/edit/angular-5ll5i7-a6je6c







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 7:29









          Vikram kumar ChhajerVikram kumar Chhajer

          716




          716













          • Onclick the list-item for ex home. The side-nav is hiding fine. but i want to hide it only for small devices.

            – Empty_Soul
            Nov 28 '18 at 7:34











          • Do you want to keep it open for small devices ? or you do not want to open the menu itself for small devices ?

            – Vikram kumar Chhajer
            Nov 29 '18 at 7:19



















          • Onclick the list-item for ex home. The side-nav is hiding fine. but i want to hide it only for small devices.

            – Empty_Soul
            Nov 28 '18 at 7:34











          • Do you want to keep it open for small devices ? or you do not want to open the menu itself for small devices ?

            – Vikram kumar Chhajer
            Nov 29 '18 at 7:19

















          Onclick the list-item for ex home. The side-nav is hiding fine. but i want to hide it only for small devices.

          – Empty_Soul
          Nov 28 '18 at 7:34





          Onclick the list-item for ex home. The side-nav is hiding fine. but i want to hide it only for small devices.

          – Empty_Soul
          Nov 28 '18 at 7:34













          Do you want to keep it open for small devices ? or you do not want to open the menu itself for small devices ?

          – Vikram kumar Chhajer
          Nov 29 '18 at 7:19





          Do you want to keep it open for small devices ? or you do not want to open the menu itself for small devices ?

          – Vikram kumar Chhajer
          Nov 29 '18 at 7:19


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53512602%2fclosing-side-nav-on-clicking-router-link-for-small-devices%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)