import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Router } from "@angular/router"; import { Observable } from 'rxjs/Observable'; import { tap, catchError } from 'rxjs/operators'; import { of } from 'rxjs/observable/of'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.scss'] }) export class HomeComponent implements OnInit { registerbool: boolean; toggleButton: boolean signupData = { username:'', password:'' }; loginData = { username: '', password: '' }; message = ''; messageR = ''; data: any; test: any; constructor(private http: HttpClient, private router: Router) { this.registerbool = false; this.toggleButton = false; } showregister() { this.registerbool = !this.registerbool; } toggleCheckbox() { this.toggleButton = !this.toggleButton; } login() { this.http.post('/api/signin', this.loginData).subscribe(resp => { this.data = resp; localStorage.setItem('jwtToken', this.data.token); this.router.navigate(['main', this.data.token]); }, err => { this.message = err.error.msg; }); } signup() { this.http.post('/api/signup',this.signupData).subscribe(resp => { this.showregister(); }, err => { this.messageR = err.error.msg; }); } facebook() { console.log('teteeeeeeee'); this.http.get('/api/facebook').subscribe(resp => { this.router.navigate(['main']); }, err => { this.message = err.error.msg; }); } showCookies() { document.getElementById('openModalButton').click(); } ngOnInit() { setTimeout(() => { this.showCookies(); }, 1000); ; } }