This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
FoodLoop-Web/src/app/pages/login.component.ts

52 lines
1.1 KiB
TypeScript
Raw Normal View History

import { Component } from '@angular/core';
2017-05-10 12:50:54 +00:00
import { Validators, FormBuilder, FormGroup } from '@angular/forms';
import { Http, Response } from '@angular/http';
import { ApiService } from '../providers/api-service';
2017-05-10 15:26:57 +00:00
import {Router } from '@angular/router';
2017-05-10 12:50:54 +00:00
import 'rxjs/add/operator/map';
@Component({
2017-05-10 12:50:54 +00:00
templateUrl: 'login.component.html',
providers: [ApiService]
})
export class LoginComponent {
2017-05-10 12:50:54 +00:00
signin: FormGroup;
ageRanges: Object[];
constructor(
private http: Http,
private formBuilder: FormBuilder,
2017-05-10 15:26:57 +00:00
private router: Router,
2017-05-10 12:50:54 +00:00
private api: ApiService
) {
this.api.getAgeRanges()
.subscribe(
result => {
console.log(result);
this.ageRanges = result.ages;
}
);
this.signin = this.formBuilder.group({
email: ['', [Validators.required]],
password: ['', [Validators.required]],
});
}
onSubmit() {
console.log(this.signin.value);
2017-05-10 15:26:57 +00:00
this.api
2017-05-10 12:50:54 +00:00
.register(this.signin.value)
.subscribe(
result => {
2017-05-10 15:26:57 +00:00
console.log('logged in!');
this.router.navigate(['/dashboard'])
2017-05-10 12:50:54 +00:00
},
error => {
console.log( error._body );
}
);
}
2017-05-10 12:50:54 +00:00
}