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) {

}
}









share|improve this question
























  • 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

















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) {

}
}









share|improve this question
























  • 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















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) {

}
}









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 3:26









georgeawg

32k104865




32k104865










asked Nov 18 at 2:43









Jonathon Hambleton

62




62












  • 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




















  • 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


















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














1 Answer
1






active

oldest

votes

















up vote
2
down vote













You can have two different layouts in your application




  1. Blank Layout //it has no sidebar

  2. 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] }]
};





share|improve this answer





















  • 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













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',
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%2f53357430%2fcreating-conditional-partials-with-ngif%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























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




  1. Blank Layout //it has no sidebar

  2. 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] }]
};





share|improve this answer





















  • 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

















up vote
2
down vote













You can have two different layouts in your application




  1. Blank Layout //it has no sidebar

  2. 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] }]
};





share|improve this answer





















  • 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















up vote
2
down vote










up vote
2
down vote









You can have two different layouts in your application




  1. Blank Layout //it has no sidebar

  2. 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] }]
};





share|improve this answer












You can have two different layouts in your application




  1. Blank Layout //it has no sidebar

  2. 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] }]
};






share|improve this answer












share|improve this answer



share|improve this answer










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 using ngStyle, 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












  • @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


















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




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]