login.component.ts 1018 Bytes
import { Component, OnInit } from '@angular/core';
import { LoginService } from './login.service';
import { Router } from '@angular/router';

@Component({
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss'],
  providers: [LoginService]
})
export class LoginComponent implements OnInit {

  loginLoading: boolean = false;
  configuracionEstacion: boolean = false;
  usuario: object = {};

  constructor(private loginService: LoginService, private router: Router) { }

  ngOnInit() {

    let glnPrevius = localStorage.getItem('gln')
    if (glnPrevius) {
      this.usuario['gln'] = glnPrevius;
    }
  }

  ingresar() {

    this.loginLoading = true;
      this.loginService.getLogin(this.usuario).subscribe(login => {
        if(login['data'] == 'ok') {
          localStorage.setItem('gln', this.usuario['gln'])
          this.router.navigateByUrl('/home');
        } else {
          alert('No se encontró la estación');
          this.loginLoading = false;
        }
      });
  }
}