2017-04-09 64 views
0

我創建了一個ionic2註冊頁面。在註冊頁面上,我創建了一個下拉菜單,用戶可以選擇他們的血型。我正試圖將選定的血型發送到Backand數據庫。我不確定我做錯了什麼,因爲選擇的血型沒有出現在Backand中。ionic2發送對象數據到Backand

signup.ts

import {Component} from '@angular/core'; 
import { BackandService } from '@backand/angular2-sdk' 
import { LoginPage } from '../login/login'; 
import { AlertController } from 'ionic-angular'; 

@Component({ 
    templateUrl: 'signup.html', 
    selector: 'page-signup', 
}) 

export class SignupPage { 

    email:string = ''; 
    firstName:string = ''; 
    lastName:string = ''; 
    signUpPassword: string = ''; 
    confirmPassword: string = ''; 
    bloodType: Object = {}; 


    constructor(private backand: BackandService, private alertCtrl: 
    AlertController) {} 


    public signUp() { 

    this.backand.signup(this.firstName, this.lastName, this.email,this.signUpPassword, this.confirmPassword, this.bloodType) 
    .then((res: any) => 
    { 
    let alert = this.alertCtrl.create({ 
    subTitle: 'Thank you for signing up.', 
    buttons:['Login'] 
    }); 
    alert.present(); 
    this.email = this.signUpPassword = this.confirmPassword = this.firstName= this.lastName = this.bloodType = ''; 
    } 
    ); 
    } 
} 

signup.html

<ion-item> 
    <ion-label>Select Your Blood Type</ion-label> 
    <ion-select type="text" (input)="bloodType = $event.target.value" ng-model="bloodType"> 
     <ion-option>O Positive</ion-option> 
     <ion-option> O Negative</ion-option> 
     <ion-option> A Positive</ion-option> 
     <ion-option> A Negative</ion-option> 
     <ion-option> B Positive</ion-option> 
     <ion-option> B Negative</ion-option> 
     <ion-option> AB Positive</ion-option> 
     <ion-option> AB Negative</ion-option> 
     <ion-option> Unknown</ion-option> 
    </ion-select> 
<ion-item> 
+0

沒有工作。出錯了。 – pinkco12

+0

error_handler.js:54 EXCEPTION:未捕獲(承諾):[object Object] – pinkco12

+0

看來你有一個'ion-select'的問題。請參閱這裏的文檔。 https://ionicframework.com/docs/api/components/select/Select/ – Sampath

回答

0

我想通了自己。在signup.ts它應該是,

this.backand.signup(this.firstName, this.lastName, this.email,this.signUpPassword, this.confirmPassword, {"bloodType": this.bloodType}) 

在signup.html應該

<ion-select type="text" (input)="bloodType = $event.target.value" [(ng-model)]="bloodType">