Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component } from '@angular/core';
- import { NavController, NavParams, AlertController } from 'ionic-angular';
- import { User } from '../../user-model';
- import { Http, Headers } from '@angular/http';
- import 'rxjs/add/operator/map';
- @Component({
- selector: 'page-signup',
- templateUrl: 'signup.html'
- })
- export class Signup{
- user: User = {
- name: "",
- username: "",
- email: "",
- password: ""
- };
- confirmPassword: string;
- url: string;
- headers: Headers;
- constructor(public navCtrl: NavController, public navParams: NavParams, public alertCtrl: AlertController, public http: Http) {
- this.headers = new Headers();
- this.headers.append('content-type', 'application/x-www-from-urlencoded');
- this.headers.append('cache-control', 'no-cache');
- this.headers.append( 'x-apikey', 'c0b179acd662d52601db1236cdbaf50fdfa31');
- }
- ionViewDidLoad() {
- console.log('ionViewDidLoad SignupPage');
- }
- goToLogin(){
- this.navCtrl.pop();
- }
- signup(){
- if(this.user.password != this.confirmPassword){
- this.alertCtrl.create({
- title: "Error",
- message: "Passwords do not match. Please retry.",
- buttons: ['OK']
- }).present();
- return;
- }
- this.url = "https://fiszki-32b3.restdb.io/rest/uzytkownik";
- this.http.post(this.url, this.user,{headers: this.headers})
- .map(res =>res.json())
- .subscribe(res => {
- console.log(res);
- },err => {
- console.log(err);
- });
- }
- }
Add Comment
Please, Sign In to add comment