How to use the login.html

Forum rules
Please note that response time for technical support is within 3-5 business days.
Post Reply
williamjieh
Posts: 5
Joined: 01 Jul 2017, 18:10

05 Aug 2017, 00:59

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

williamjieh
Posts: 5
Joined: 01 Jul 2017, 18:10

08 Aug 2017, 01:05

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:

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>

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

15 Aug 2017, 17:10

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.

paulswan
Posts: 94
Joined: 27 Apr 2017, 08:19

17 Aug 2017, 01:33

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:

Code: Select all

<router-outlet></router-outlet>
The app.component.html will also just have the 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}
];
The routes in the AuthenticationModule will be:

Code: Select all

{path: '', redirectTo: 'login', pathMatch: 'full'},
{path: 'login', component: LoginComponent},
{path: 'logout', component: LogoutComponent, canActivate: [AuthGuardService]}
The LoginComponent will just have what's inside the <body> tag of login.html or something similar.

I hope this helps.

Post Reply

Return to “Ultima - PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 20 guests