Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ul class="list-group">
- <li *ngIf="isLoggedIn" (click)="onLogout()">Logout</li>
- </ul>
- import { Component, OnInit } from '@angular/core';
- import { HttpService } from '../../http.service';
- import { Subscription } from 'rxjs';
- @Component({
- selector: 'app-menu-items',
- templateUrl: './menu-items.component.html',
- styleUrls: ['./menu-items.component.css']
- })
- export class MenuItemsComponent implements OnInit {
- isLoggedIn: boolean = false;
- constructor(private httpService: HttpService) {
- }
- ngOnInit() {
- }
- onSignout(){
- this.isLoggedIn = false;
- localStorage.removeItem('currentUser');
- }
- }
- onSignin(){
- const username = this.loginForm.get('username').value;
- const password = this.loginForm.get('password').value;
- this.httpServie.sendDataLogin("grant_type=password&username=" + username + "&password=" + password)
- .subscribe(
- data => {
- this.token = JSON.parse(data["_body"]).access_token
- this.username = JSON.parse(data["_body"]).userName
- localStorage.setItem('currentUser', JSON.stringify({username: this.username, token: this.token}))
- },
- err => {
- if (err.error instanceof Error) {
- this.ServerErrorMsg = err.error.message;
- } else {
- const returnArray = [];
- this.ServerErrorMsg = JSON.parse(err._body).error_description + "n";
- }
- }
- );
- }
Add Comment
Please, Sign In to add comment