Closing side-nav on clicking router link for small devices
I am using side-nav
component in my project for routing between the components,which looks like this:
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
add a comment |
I am using side-nav
component in my project for routing between the components,which looks like this:
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
add a comment |
I am using side-nav
component in my project for routing between the components,which looks like this:
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
I am using side-nav
component in my project for routing between the components,which looks like this:
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
angular angular-material angular6 angular-routing
edited Nov 28 '18 at 7:15
Empty_Soul
asked Nov 28 '18 at 5:18
Empty_SoulEmpty_Soul
36012
36012
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can do this by
- providing a reference to
mat-sidenav
as<mat-sidenav #snav
- Using this reference to
toggle
orclose
themat-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
Let me try your answer.
– Empty_Soul
Nov 28 '18 at 7:11
In your code thetoggle-menu (i,e side-nav)
is already present for larger screens also. I want to maketoggle-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
|
show 3 more comments
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();
}
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
add a comment |
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
Onclick the list-item for exhome
. 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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
You can do this by
- providing a reference to
mat-sidenav
as<mat-sidenav #snav
- Using this reference to
toggle
orclose
themat-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
Let me try your answer.
– Empty_Soul
Nov 28 '18 at 7:11
In your code thetoggle-menu (i,e side-nav)
is already present for larger screens also. I want to maketoggle-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
|
show 3 more comments
You can do this by
- providing a reference to
mat-sidenav
as<mat-sidenav #snav
- Using this reference to
toggle
orclose
themat-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
Let me try your answer.
– Empty_Soul
Nov 28 '18 at 7:11
In your code thetoggle-menu (i,e side-nav)
is already present for larger screens also. I want to maketoggle-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
|
show 3 more comments
You can do this by
- providing a reference to
mat-sidenav
as<mat-sidenav #snav
- Using this reference to
toggle
orclose
themat-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
You can do this by
- providing a reference to
mat-sidenav
as<mat-sidenav #snav
- Using this reference to
toggle
orclose
themat-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
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 thetoggle-menu (i,e side-nav)
is already present for larger screens also. I want to maketoggle-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
|
show 3 more comments
Let me try your answer.
– Empty_Soul
Nov 28 '18 at 7:11
In your code thetoggle-menu (i,e side-nav)
is already present for larger screens also. I want to maketoggle-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
|
show 3 more comments
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();
}
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
add a comment |
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();
}
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
add a comment |
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();
}
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();
}
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
add a comment |
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
add a comment |
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
Onclick the list-item for exhome
. 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
add a comment |
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
Onclick the list-item for exhome
. 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
add a comment |
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
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
answered Nov 28 '18 at 7:29
Vikram kumar ChhajerVikram kumar Chhajer
716
716
Onclick the list-item for exhome
. 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
add a comment |
Onclick the list-item for exhome
. 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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