I am trying to create a login page that quite diffirent from main application layout so I try to seperate login.component from app.component I also use bodyclass property to set class attribute of body element I also want to hear any experience that handle this and say my way is wrong or fine.
Here how my index.html, login.component.ts and app.component.ts files looks;
login.component.ts
import { Component } from '@angular/core';
import {Auth} from '../auth/auth.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: [
'../../assets/css/colors/cyan.css'
]
})
export class LoginComponent {
bodyclass = 'body-login-class';
constructor(private auth:Auth){}
}
app.component.ts
import { Component } from '@angular/core';
import {Auth} from './auth/auth.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css',
'assets/css/colors/default.css',
...
]
})
export class AppComponent {
bodyclass = 'body-general-class';
constructor(private auth:Auth){}
}
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>AngTs19December</title>
<base href="/">
<script src="http://cdn.auth0.com/js/lock/10.2/lock.min.js"></script>
</head>
<body [class]="bodyclass">
<app-root>Loading...</app-root>
<app-login></app-login>
<!-- Global Plugin JavaScript -->
...
</body>
</html>
I never come across any example like useage
app-root and app-login
in same file, so it bothers me.. anyway here is the error I face when I run this.

and last; routes.ts Login page must be the page welcomes user always it they are signed in
import {ModuleWithProviders} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {AuthGuard} from './auth/auth.guard';
import {HomeComponent} from './home/home.component';
import {LoginComponent} from './login/login.component';
const appRoutes: Routes=[
{
path:'home',
component:HomeComponent,
canActivate:[AuthGuard]
},
{
path:'',
component:LoginComponent
}
];
export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);