preparing form3 post

parent b6f092c5
import {Component} from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { Student } from '../students/student';
import {
FormControl,
......@@ -9,37 +12,55 @@ import {
selector: 'form3',
template: `
<div>
<form (submit)="onSubmit(studentform)" class="col-sm-8">
<form #studentform="ngForm" (submit)="onSubmit(studentform)" class="col-sm-8">
<div class="form-group">
<label>Ονοματεπώνυμο</label>
<input type="text" [(ngModel)]="studentform.name" name="name"
<label>Όνομα</label>
<input type="text" [(ngModel)]="student.name" name="name"
required class="form-control" />
</div>
<div class="form-group">
<label>Ονοματεπώνυμο</label>
<input type="text" [(ngModel)]="studentform.surname" name="surname"
<label>Επώνυμο</label>
<input type="text" [(ngModel)]="student.surname" name="surname"
required class="form-control" />
</div>
<div class="form-group">
<label>Διεύθυνση</label>
<input type="text" [(ngModel)]="studentform.address" name="address"
<input type="text" [(ngModel)]="student.address" name="address"
required class="form-control" />
</div>
<div class="form-group">
<label>Ημερομηνία Γέννησης</label>
<input type="date" [(ngModel)]="studentform.birthdate"
<input type="date" [(ngModel)]="student.birthdate"
class="form-control" name="birthdate" />
</div>
<input type="submit" value="Υποβολή" class="btn btn-success" />
<input type="submit" [disabled]="!studentform.valid" value="Υποβολή" class="btn btn-success" />
</form>
</div>
`
})
export default class Form3 {
public studentform: any = {};
public student;
constructor(private http: Http) {
this.student = new Student(0,'','','','','1','');
}
onSubmit(studentform: any) {
// console.log(studentform);
console.log(studentform.surname + "..." + studentform.name + "..." + studentform.address+ "..." + studentform.birthdate);
// console.log(studentform.surname + "..." + studentform.name + "..." + studentform.address+ "..." + studentform.birthdate);
this.student._links = '{"type": {"href": "http://eepal.dev/drupal/rest/type/node/student"}}';
let headers = {
"Authorization": "Basic YWRtaW46MTIzcXdl", // encoded user/pass - this is admin/123qwe
"Content-Type": "application/hal+json",
};
console.log(this.student);
this.http.post('http://eepal.dev/drupal/entity/student',studentform,headers)
// Call map on the response observable to get the parsed people object
.map((res: Response) => res.json())
.subscribe(success => console.log("success post"), // put the data returned from the server in our variable
error => console.log("Error HTTP GET Service"), // in case of failure show this message
() => console.log("write this message anyway"));//run this code in all cases);
}
}
......@@ -4,6 +4,8 @@ export class Student {
public name: string,
public surname: string,
public address: string,
public studentclass_id:string
public birthDate: string,
public studentclass_id:string,
public _links:string
){}
}
......@@ -10,8 +10,6 @@ import 'rxjs/add/operator/toPromise';
@Component({
selector: 'students-list',
template: `
<p>{{ students[0].name }}</p>
<p>{{ students[1].name }}</p>
<div>
<ng2-smart-table [settings]="settings" [source]="data"></ng2-smart-table>
</div>
......@@ -45,21 +43,19 @@ import 'rxjs/add/operator/toPromise';
constructor(private http: Http) {
this.http = http;
}
ngOnInit(){
this.data = [];
this.students = [];
this.students[0] = new Student(1, '', '', '', '');
this.students[1] = new Student(2, '', '', '', '');
this.getStudents(this.http);//called after the constructor and called after the first ngOnChanges()
}
getStudents(http: Http) {
// this.http.get('http://eduslim2.minedu.gov.gr/drupal/students/list')
// this.data = new ServerDataSource(http, {endPoint: 'http://eepal.dev/drupal/students/list'});
this.data = new ServerDataSource(http, {endPoint: 'http://eduslim2.minedu.gov.gr/drupal/students/list'});
this.data = new ServerDataSource(http, {endPoint: 'http://eepal.dev/drupal/students/list'});
// this.data = new ServerDataSource(http, {endPoint: 'http://eduslim2.minedu.gov.gr/drupal/students/list'});
/* this.http.get('http://eepal.dev/drupal/students/list')
// Call map on the response observable to get the parsed people object
.map(response => <Student[]>response.json())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment