2017-04-27 15:29:31 +01:00
import { Component } from '@angular/core' ;
2017-05-09 13:39:48 +01:00
import { Validators , FormBuilder , FormGroup } from '@angular/forms' ;
2017-04-27 22:50:11 +01:00
import { Http , Response } from '@angular/http' ;
2017-05-09 13:39:48 +01:00
import { ApiService } from '../providers/api-service' ;
import 'rxjs/add/operator/map' ;
2017-04-27 15:29:31 +01:00
@Component ( {
2017-05-09 13:39:48 +01:00
templateUrl : 'register.component.html' ,
providers : [ ApiService ]
2017-04-27 15:29:31 +01:00
} )
export class RegisterComponent {
2017-05-09 13:39:48 +01:00
signup : FormGroup ;
ageRanges : Object [ ] ;
2017-05-09 17:43:48 +01:00
constructor (
private http : Http ,
private formBuilder : FormBuilder ,
private api : ApiService
) {
this . api . getAgeRanges ( )
. subscribe (
result = > {
console . log ( result ) ;
this . ageRanges = result . ages ;
}
) ;
this . signup = this . formBuilder . group ( {
token : [ '' , [ Validators . required ] ] ,
full_name : [ '' , [ Validators . required ] ] ,
display_name : [ '' , [ Validators . required ] ] ,
email : [ '' , [ Validators . required ] ] ,
postcode : [ '' , [ Validators . required ] ] ,
age_range : [ '' , [ Validators . required ] ] ,
password : [ '' , [ Validators . required ] ] ,
} ) ;
2017-05-09 13:39:48 +01:00
}
onSubmit() {
console . log ( this . signup . value ) ;
2017-05-10 13:50:54 +01:00
this . peopleService
. register ( this . signup . value )
. subscribe (
result = > {
console . log ( registered ! ) ;
} ,
error = > {
console . log ( error . _body ) ;
}
) ;
2017-04-27 22:50:11 +01:00
}
2017-04-27 15:29:31 +01:00
2017-05-09 13:39:48 +01:00
}