Created
July 21, 2018 19:38
-
-
Save ozgurrgul/9287b068c0b5e87e575f1cc7ba284b5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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