Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { FormsModule } from "@angular/forms";
- import { AppRoutingModule } from './app-routing.module';
- import { AppComponent } from './app.component';
- import { LoginPageComponent } from './login-page/login-page.component';
- import { NavHeaderComponent } from './nav-header/nav-header.component';
- import {LoginService} from "./login.service";
- @NgModule({
- declarations: [
- AppComponent,
- LoginPageComponent,
- NavHeaderComponent
- ],
- imports: [
- BrowserModule,
- AppRoutingModule,
- FormsModule
- ],
- bootstrap: [AppComponent]
- })
- export class AppModule { }
- import { Component } from '@angular/core';
- import { LoginService } from "./login.service";
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.scss'],
- })
- export class AppComponent {
- private title : string = '*******';
- private isLoggedIn : Boolean ;
- constructor(loginService : LoginService){
- this.isLoggedIn = loginService.CheckLoginStatus();
- }
- }
- import { Injectable } from '@angular/core';
- @Injectable({
- providedIn: 'root'
- })
- export class LoginService {
- private username = "***";
- private password = "***";
- private isLogin : Boolean = false;
- // Variable to check whether the user has logged in or not
- constructor(isLogin:Boolean) {
- this.isLogin = isLogin;
- }
- /* Function to check login status */
- CheckLoginStatus() {
- return this.isLogin;
- }
- /* Function to call after the user is logged in */
- HasLoggedIn() {
- this.isLogin = true;
- }
- /* Function to call after the user is logged out */
- HasLoggedOut() {
- this.isLogin = false;
- }
- /*Function to validate User */
- validateLogin(username : string , password : string)
- {
- if(username===this.username && password===this.password)
- this.HasLoggedIn();
- return this.isLogin;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement