Added post and get function
This commit is contained in:
parent
cf721cc4af
commit
ca86d48e13
5
client/Nightr/src/app/app.component.css
Normal file
5
client/Nightr/src/app/app.component.css
Normal file
|
@ -0,0 +1,5 @@
|
|||
.float-btn-container
|
||||
{
|
||||
margin-top: 35%;
|
||||
margin-left: 20%;
|
||||
}
|
|
@ -1,3 +1,9 @@
|
|||
<StackLayout>
|
||||
<ns-my-button></ns-my-button>
|
||||
<AbsoluteLayout>
|
||||
<ns-side-drawer></ns-side-drawer>
|
||||
|
||||
<StackLayout class="float-btn-container">
|
||||
<ns-my-button (tap)=onTap($event) text="Nightr"></ns-my-button>
|
||||
</StackLayout>
|
||||
|
||||
</AbsoluteLayout>
|
||||
|
||||
|
|
|
@ -1,8 +1,40 @@
|
|||
import { Component } from "@angular/core";
|
||||
import * as dialogs from "tns-core-modules/ui/dialogs";
|
||||
import { MyHttpPostService } from './services/my-http-post-service'
|
||||
import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures'
|
||||
|
||||
@Component({
|
||||
selector: "ns-app",
|
||||
moduleId: module.id,
|
||||
templateUrl: "./app.component.html"
|
||||
templateUrl: "./app.component.html",
|
||||
styleUrls: ['./app.component.css'],
|
||||
providers: [MyHttpPostService]
|
||||
})
|
||||
export class AppComponent { }
|
||||
export class AppComponent {
|
||||
public user: string = "";
|
||||
public pass: string = "";
|
||||
returnMessage: string = "";
|
||||
|
||||
constructor(private myHttpPostSerivce: MyHttpPostService) { }
|
||||
|
||||
public onTap(args: GestureEventData): any {
|
||||
this.submit();
|
||||
dialogs.confirm("Should be result").then(result => {
|
||||
console.log("Dialog result: " + result);
|
||||
});
|
||||
}
|
||||
|
||||
public submit(): void {
|
||||
this.makePostRequest();
|
||||
}
|
||||
|
||||
private makePostRequest(): void {
|
||||
console.log('Reached makepostRequest');
|
||||
this.myHttpPostSerivce
|
||||
.postData({ username: this.user, password: this.pass })
|
||||
.subscribe(res => {
|
||||
console.log('This is res', res);
|
||||
this.returnMessage = (<any>res).json.data.username;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@ import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
|
|||
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
|
||||
|
||||
import { AppComponent } from "./app.component";
|
||||
import { MyButtonComponent } from './my-button/my-button.component';
|
||||
import { MyButtonComponent } from './component/my-button/my-button.component';
|
||||
import { NativeScriptHttpClientModule } from "nativescript-angular/http-client";
|
||||
|
||||
// Uncomment and add to NgModule imports if you need to use two-way binding
|
||||
// import { NativeScriptFormsModule } from "nativescript-angular/forms";
|
||||
|
@ -16,6 +17,7 @@ import { MyButtonComponent } from './my-button/my-button.component';
|
|||
],
|
||||
imports: [
|
||||
NativeScriptModule,
|
||||
NativeScriptHttpClientModule,
|
||||
],
|
||||
declarations: [
|
||||
AppComponent,
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
/* Add mobile styles for the component here. */
|
|
@ -1,3 +0,0 @@
|
|||
<StackLayout>
|
||||
<Button text="my-button works!" class="btn btn-primary"></Button>
|
||||
</StackLayout>
|
|
@ -1,16 +0,0 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'ns-my-button',
|
||||
templateUrl: './my-button.component.html',
|
||||
styleUrls: ['./my-button.component.css'],
|
||||
moduleId: module.id,
|
||||
})
|
||||
export class MyButtonComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
}
|
9
client/Nightr/src/app/services/my-http-get.service.ts
Normal file
9
client/Nightr/src/app/services/my-http-get.service.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MyHttpGetService {
|
||||
|
||||
constructor() { }
|
||||
}
|
24
client/Nightr/src/app/services/my-http-post-service.ts
Normal file
24
client/Nightr/src/app/services/my-http-post-service.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { Injectable } from "@angular/core";
|
||||
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MyHttpPostService {
|
||||
private serverUrl = "https://nightr.caspervk.net";
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
postData(data: any) {
|
||||
console.log('logged data is', data);
|
||||
let options = this.createRequestOptions();
|
||||
return this.http.post(this.serverUrl, { data }, { headers: options });
|
||||
}
|
||||
|
||||
private createRequestOptions() {
|
||||
let headers = new HttpHeaders({
|
||||
"Content-Type": "application/json"
|
||||
});
|
||||
return headers;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue