Creating conditional partials with ngIf
up vote
1
down vote
favorite
I'm looking to implement an application wide nav and subnav combination with conditional logic that shows a sidenav on a specific page. I've tried a few of the ngIf on routerLink posts here, but none have solved my issue.
app.component.html is my main container, header, and subnav, as described by the Clarity docs.
app.component.html
<div class="main-container">
<header class="header">
</header>
<nav class="subnav">
</nav>
<div class="content-container">
<div class="content-area">
<router-outlet></router-outlet>
</div>
<nav *ngIf="router.url === '/page'" class="sidenav">
</nav>
</div>
</div>
app.component.ts
class PageComponent {
constructor(public router: Router) {
}
}
angular vmware-clarity
add a comment |
up vote
1
down vote
favorite
I'm looking to implement an application wide nav and subnav combination with conditional logic that shows a sidenav on a specific page. I've tried a few of the ngIf on routerLink posts here, but none have solved my issue.
app.component.html is my main container, header, and subnav, as described by the Clarity docs.
app.component.html
<div class="main-container">
<header class="header">
</header>
<nav class="subnav">
</nav>
<div class="content-container">
<div class="content-area">
<router-outlet></router-outlet>
</div>
<nav *ngIf="router.url === '/page'" class="sidenav">
</nav>
</div>
</div>
app.component.ts
class PageComponent {
constructor(public router: Router) {
}
}
angular vmware-clarity
Can you add code inapp.component.ts
whatever you tried?
– varit05
Nov 18 at 2:49
it's the second code block
– Jonathon Hambleton
Nov 18 at 2:50
Alternatively you can add a combination of named routers with *ngIf or ngStyle or canActivate. It's definitely a choice of what is cleaner and your preference. I have used *ngIf for some menus items that need to be hidden if that is the purpose.
– Gary
Nov 18 at 6:33
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm looking to implement an application wide nav and subnav combination with conditional logic that shows a sidenav on a specific page. I've tried a few of the ngIf on routerLink posts here, but none have solved my issue.
app.component.html is my main container, header, and subnav, as described by the Clarity docs.
app.component.html
<div class="main-container">
<header class="header">
</header>
<nav class="subnav">
</nav>
<div class="content-container">
<div class="content-area">
<router-outlet></router-outlet>
</div>
<nav *ngIf="router.url === '/page'" class="sidenav">
</nav>
</div>
</div>
app.component.ts
class PageComponent {
constructor(public router: Router) {
}
}
angular vmware-clarity
I'm looking to implement an application wide nav and subnav combination with conditional logic that shows a sidenav on a specific page. I've tried a few of the ngIf on routerLink posts here, but none have solved my issue.
app.component.html is my main container, header, and subnav, as described by the Clarity docs.
app.component.html
<div class="main-container">
<header class="header">
</header>
<nav class="subnav">
</nav>
<div class="content-container">
<div class="content-area">
<router-outlet></router-outlet>
</div>
<nav *ngIf="router.url === '/page'" class="sidenav">
</nav>
</div>
</div>
app.component.ts
class PageComponent {
constructor(public router: Router) {
}
}
angular vmware-clarity
angular vmware-clarity
edited Nov 18 at 3:26
georgeawg
32k104865
32k104865
asked Nov 18 at 2:43
Jonathon Hambleton
62
62
Can you add code inapp.component.ts
whatever you tried?
– varit05
Nov 18 at 2:49
it's the second code block
– Jonathon Hambleton
Nov 18 at 2:50
Alternatively you can add a combination of named routers with *ngIf or ngStyle or canActivate. It's definitely a choice of what is cleaner and your preference. I have used *ngIf for some menus items that need to be hidden if that is the purpose.
– Gary
Nov 18 at 6:33
add a comment |
Can you add code inapp.component.ts
whatever you tried?
– varit05
Nov 18 at 2:49
it's the second code block
– Jonathon Hambleton
Nov 18 at 2:50
Alternatively you can add a combination of named routers with *ngIf or ngStyle or canActivate. It's definitely a choice of what is cleaner and your preference. I have used *ngIf for some menus items that need to be hidden if that is the purpose.
– Gary
Nov 18 at 6:33
Can you add code in
app.component.ts
whatever you tried?– varit05
Nov 18 at 2:49
Can you add code in
app.component.ts
whatever you tried?– varit05
Nov 18 at 2:49
it's the second code block
– Jonathon Hambleton
Nov 18 at 2:50
it's the second code block
– Jonathon Hambleton
Nov 18 at 2:50
Alternatively you can add a combination of named routers with *ngIf or ngStyle or canActivate. It's definitely a choice of what is cleaner and your preference. I have used *ngIf for some menus items that need to be hidden if that is the purpose.
– Gary
Nov 18 at 6:33
Alternatively you can add a combination of named routers with *ngIf or ngStyle or canActivate. It's definitely a choice of what is cleaner and your preference. I have used *ngIf for some menus items that need to be hidden if that is the purpose.
– Gary
Nov 18 at 6:33
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
You can have two different layouts in your application
- Blank Layout //it has no sidebar
- Main Layout //it has your sidebar
Your router
will look like this
const routes: Routes = [
{
path: '',
component: BlankLayoutComponent,
children: [
{ path: '', redirectTo: 'logincustomer',pathMatch:'full' },
{ path: 'logincustomer', component: LoginComponent }
]
},
{
path: 'user',
component: MainLayoutComponent,
canActivate: [AuthGuard],
children: [
{ path: 'user', redirectTo:'dashboard', pathMatch: 'full', canActivate: [AuthGuard] }]
};
Fantastic, thank you! Could I more simply arrive at this solution with *ngStyle using a display: none property?
– Jonathon Hambleton
Nov 18 at 5:51
@JonathonHambleton you can also do it usingngStyle
, but the way shown above is very effective for large scale applications.
– Abdul Basit
Nov 18 at 6:12
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You can have two different layouts in your application
- Blank Layout //it has no sidebar
- Main Layout //it has your sidebar
Your router
will look like this
const routes: Routes = [
{
path: '',
component: BlankLayoutComponent,
children: [
{ path: '', redirectTo: 'logincustomer',pathMatch:'full' },
{ path: 'logincustomer', component: LoginComponent }
]
},
{
path: 'user',
component: MainLayoutComponent,
canActivate: [AuthGuard],
children: [
{ path: 'user', redirectTo:'dashboard', pathMatch: 'full', canActivate: [AuthGuard] }]
};
Fantastic, thank you! Could I more simply arrive at this solution with *ngStyle using a display: none property?
– Jonathon Hambleton
Nov 18 at 5:51
@JonathonHambleton you can also do it usingngStyle
, but the way shown above is very effective for large scale applications.
– Abdul Basit
Nov 18 at 6:12
add a comment |
up vote
2
down vote
You can have two different layouts in your application
- Blank Layout //it has no sidebar
- Main Layout //it has your sidebar
Your router
will look like this
const routes: Routes = [
{
path: '',
component: BlankLayoutComponent,
children: [
{ path: '', redirectTo: 'logincustomer',pathMatch:'full' },
{ path: 'logincustomer', component: LoginComponent }
]
},
{
path: 'user',
component: MainLayoutComponent,
canActivate: [AuthGuard],
children: [
{ path: 'user', redirectTo:'dashboard', pathMatch: 'full', canActivate: [AuthGuard] }]
};
Fantastic, thank you! Could I more simply arrive at this solution with *ngStyle using a display: none property?
– Jonathon Hambleton
Nov 18 at 5:51
@JonathonHambleton you can also do it usingngStyle
, but the way shown above is very effective for large scale applications.
– Abdul Basit
Nov 18 at 6:12
add a comment |
up vote
2
down vote
up vote
2
down vote
You can have two different layouts in your application
- Blank Layout //it has no sidebar
- Main Layout //it has your sidebar
Your router
will look like this
const routes: Routes = [
{
path: '',
component: BlankLayoutComponent,
children: [
{ path: '', redirectTo: 'logincustomer',pathMatch:'full' },
{ path: 'logincustomer', component: LoginComponent }
]
},
{
path: 'user',
component: MainLayoutComponent,
canActivate: [AuthGuard],
children: [
{ path: 'user', redirectTo:'dashboard', pathMatch: 'full', canActivate: [AuthGuard] }]
};
You can have two different layouts in your application
- Blank Layout //it has no sidebar
- Main Layout //it has your sidebar
Your router
will look like this
const routes: Routes = [
{
path: '',
component: BlankLayoutComponent,
children: [
{ path: '', redirectTo: 'logincustomer',pathMatch:'full' },
{ path: 'logincustomer', component: LoginComponent }
]
},
{
path: 'user',
component: MainLayoutComponent,
canActivate: [AuthGuard],
children: [
{ path: 'user', redirectTo:'dashboard', pathMatch: 'full', canActivate: [AuthGuard] }]
};
answered Nov 18 at 4:38
Abdul Basit
1458
1458
Fantastic, thank you! Could I more simply arrive at this solution with *ngStyle using a display: none property?
– Jonathon Hambleton
Nov 18 at 5:51
@JonathonHambleton you can also do it usingngStyle
, but the way shown above is very effective for large scale applications.
– Abdul Basit
Nov 18 at 6:12
add a comment |
Fantastic, thank you! Could I more simply arrive at this solution with *ngStyle using a display: none property?
– Jonathon Hambleton
Nov 18 at 5:51
@JonathonHambleton you can also do it usingngStyle
, but the way shown above is very effective for large scale applications.
– Abdul Basit
Nov 18 at 6:12
Fantastic, thank you! Could I more simply arrive at this solution with *ngStyle using a display: none property?
– Jonathon Hambleton
Nov 18 at 5:51
Fantastic, thank you! Could I more simply arrive at this solution with *ngStyle using a display: none property?
– Jonathon Hambleton
Nov 18 at 5:51
@JonathonHambleton you can also do it using
ngStyle
, but the way shown above is very effective for large scale applications.– Abdul Basit
Nov 18 at 6:12
@JonathonHambleton you can also do it using
ngStyle
, but the way shown above is very effective for large scale applications.– Abdul Basit
Nov 18 at 6:12
add a comment |
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%2f53357430%2fcreating-conditional-partials-with-ngif%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
Can you add code in
app.component.ts
whatever you tried?– varit05
Nov 18 at 2:49
it's the second code block
– Jonathon Hambleton
Nov 18 at 2:50
Alternatively you can add a combination of named routers with *ngIf or ngStyle or canActivate. It's definitely a choice of what is cleaner and your preference. I have used *ngIf for some menus items that need to be hidden if that is the purpose.
– Gary
Nov 18 at 6:33