feat(demo): post the form

This commit is contained in:
Ken Sodemann
2018-02-13 15:44:30 -06:00
parent 89d4e2db22
commit ee887a4842
9 changed files with 318 additions and 334 deletions

View File

@ -1,8 +1,10 @@
import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { PostTestService } from './post-test/post-test.service';
import { IonicAngularModule, IonicRouterModule } from '@ionic/angular';
@ -11,10 +13,12 @@ import { IonicAngularModule, IonicRouterModule } from '@ionic/angular';
imports: [
AppRoutingModule,
BrowserModule,
HttpClientModule,
IonicAngularModule.forRoot(),
IonicRouterModule.forRoot()
],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [PostTestService]
})
export class AppModule {}
export class AppModule { }

View File

@ -82,7 +82,7 @@
</ion-list>
</ion-content>
<ion-footer>
<ion-button expand="block" [disabled]="myForm.invalid" (click)="save()">
<ion-button expand="block" [disabled]="myForm.invalid" (click)="save(myForm.value)">
<ion-icon name="save" slot="start"></ion-icon>Looks Good to Me</ion-button>
</ion-footer>
</ion-page>

View File

@ -1,7 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { HomePageComponent } from '../home-page/home-page.component';
import { HomePage } from '../../../e2e/home.po';
import { PostTestService } from '../post-test/post-test.service';
@Component({
selector: 'app-form-sample-page',
@ -22,24 +21,12 @@ export class FormSamplePageComponent implements OnInit {
desiredSalary: number;
levelOfHappy: number;
constructor(private router: Router) { }
constructor(private postman: PostTestService, private router: Router) { }
ngOnInit() { }
save() {
const data = {
firstName: this.firstName,
lastName: this.lastName,
title: this.jobTitle,
beer: this.drinkBeers,
tea: this.drinkTeas,
coffee: this.makeCoffee,
feed: this.feedEngineers,
description: this.selfDescription,
salary: this.desiredSalary,
happy: this.levelOfHappy
};
console.log('I would submit: ', data);
save(data: any) {
this.postman.post(data).subscribe(res => console.log(res));
this.router.navigate(['home']);
}
}

View File

@ -0,0 +1,15 @@
import { TestBed, inject } from '@angular/core/testing';
import { PostTestService } from './post-test.service';
describe('PostTestService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [PostTestService]
});
});
it('should be created', inject([PostTestService], (service: PostTestService) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,12 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class PostTestService {
constructor(private http: HttpClient) { }
post(data: any): Observable<any> {
return this.http.post('http://localhost:5000/test', data);
}
}