Skip to content

Instantly share code, notes, and snippets.

@ozgurrgul
Created July 21, 2018 19:38
Show Gist options
  • Save ozgurrgul/9287b068c0b5e87e575f1cc7ba284b5f to your computer and use it in GitHub Desktop.
Save ozgurrgul/9287b068c0b5e87e575f1cc7ba284b5f to your computer and use it in GitHub Desktop.
import {Component} from '@angular/core';
import {ApiService} from '../api.service';
import {CustomerService} from '../customer.service';
import {Router} from '@angular/router';
@Component({
selector: 'app-login-page',
templateUrl: './login-page.component.html',
styleUrls: ['./login-page.component.css']
})
export class LoginPageComponent {
email = 'peter@klaven';
password = 'cityslicka';
constructor(private api: ApiService, private customer: CustomerService, private router: Router) {
}
tryLogin() {
this.api.login(
this.email,
this.password
)
.subscribe(
r => {
if (r.token) {
this.customer.setToken(r.token);
this.router.navigateByUrl('/dashboard');
}
},
r => {
alert(r.error.error);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment