Hi All,
I'm trying to add login page in my angular app, I found the login.html template page under :
/src/assets/pages/login.html
but this html looks like not run in angular, it's outside of angular app. It's not in <app-root>.
So how should I use this login.html file to make a login page ?
Thank you
How to use the login.html
Forum rules
Please note that response time for technical support is within 3-5 business days.
Please note that response time for technical support is within 3-5 business days.
-
- Posts: 5
- Joined: 01 Jul 2017, 18:10
Finally find a way to use it.
1. create a custom structural directive, name it 'showAuthed' or what ever you like. In this directive, check if current visitor is logged or not. if Yes, show the view content; if No, do not show.
2. Copy the html code into /src/app/app.component.html file , and use it like this:
1. create a custom structural directive, name it 'showAuthed' or what ever you like. In this directive, check if current visitor is logged or not. if Yes, show the view content; if No, do not show.
2. Copy the html code into /src/app/app.component.html file , and use it like this:
Code: Select all
<!-- This is login page -->
<div *showAuthed="false">
...
</div>
<!-- This is admin home -->
<div class="layout-wrapper" [ngClass]="{'layout-compact':layoutCompact}" *showAuthed="true" >
...
</div>
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
login.html is not necessarily Angular, it is static HTML that can be used with a backend of your choice. Of course you need to post the login info to your backend. Other alternative is what you have already done with embedding login into main template.
I managed to use part of login.html as a component by using 2 layouts. The main layout is basically what you have in app.component.html and the other will just have the following:
The app.component.html will also just have the router-outlet
The router in app.routes.ts would look like this:
The routes in the AuthenticationModule will be:
The LoginComponent will just have what's inside the <body> tag of login.html or something similar.
I hope this helps.
Code: Select all
<router-outlet></router-outlet>
The router in app.routes.ts would look like this:
Code: Select all
export const routes: Routes = [
{
path: '',
component: MainLayoutComponent,
children: [
{path: '', redirectTo: 'home', pathMatch: 'full'},
{path: 'home', loadChildren: 'app/home/home.module#HomeModule', canActivate: [AuthGuardService]},
{path: 'about', loadChildren: 'app/about/about.module#AboutModule', canActivate: [AuthGuardService]},
]
},
{
path: 'authentication', component: AuthLayoutComponent,
loadChildren: 'app/authentication/authentication.module#AuthenticationModule'
},
{path: '**', component: PageNotFoundComponent}
];
Code: Select all
{path: '', redirectTo: 'login', pathMatch: 'full'},
{path: 'login', component: LoginComponent},
{path: 'logout', component: LogoutComponent, canActivate: [AuthGuardService]}
I hope this helps.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 20 guests