Skip to content

Instantly share code, notes, and snippets.

@asciant
Last active January 2, 2017 05:53
Show Gist options
  • Save asciant/905dffc8535831497f8a4d7cec50e0c7 to your computer and use it in GitHub Desktop.
Save asciant/905dffc8535831497f8a4d7cec50e0c7 to your computer and use it in GitHub Desktop.
Component
<div *ngFor="let item of data | async">
{{ item.data }}
</div>
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
import { Http, Response, } from '@angular/http';
import { Headers, RequestOptions } from '@angular/http';
@Component({
moduleId: module.id,
selector: 'registration',
templateUrl: 'registration.component.html'
})
export class registrationComponent {
emailRegex = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
data$: Observable<any>; // <-- I changed this
result$;
data: any[];
registration : FormGroup;
constructor(r: FormBuilder, public http :Http){
this.registration = r.group({
'chosen_username' : [null, Validators.required],
'chosen_email' : [null, Validators.pattern(this.emailRegex)],
'chosen_password' : [null, Validators.required],
});
}
submitForm(){
const headers = new Headers();
headers.append('Content-Type', 'application/joson; charset=utf-8' );
this.data$ = this.http.get('/scripts/php/formsubmit.php', JSON.stringify(this.registration.value), headers)
.map((res:Response) => res.json());
this.result$ = this.data$.subscribe(
data => this.data = data, //Bind to view
err => {
// Log errors if any
console.log(err);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment