2016-12-06 23 views
0

我是新來的離子框架,我寫過郵件調用,我不完全知道post方法。當我在忘記密碼頁面中輸入提交按鈕時,如果用戶已經註冊,則應該顯示下一頁否則它應該顯示警報消息。 下面是我的代碼:如何寫離子後的方法?

import { Component } from '@angular/core'; 
import { configurator } from '../../providers/configurator'; 
import { NavController } from 'ionic-angular'; 
// import { LoginPage } from '../login/login'; 
import { persistence } from '../persistence/persistence'; 

    @Component({ 
    templateUrl: 'home.html' 
    }) 
    export class home { 

    public loginId = ""; 

    constructor(public navCtrl: NavController) { 

    } 
    generateOTP(newstate) { 
    console.log("invoking generateOTP FN"); 
    var _this = this; 
    this.login.generateOTP(this.loginId, function(result,data){ 
    if(result == '1') { 
    alert(data); 
    var a = document.createElement('a'); 
    a.href="OTP page"; 
    } 
    else { 
    //this.showRePasswd = this.showRePasswd; 
    alert(data); 
     } 
    }) 
    } 
    } 

這是我的離子頁:enter image description here 誰能幫我!

回答

1

我的帖子講座敬愛的在IONIC2

import { Http, Response } from '@angular/http'; 

constructor(public navCtrl: NavController, private http: Http) { } 

this.http.post(`${POST_URL}/log/add`, JSON.stringify(this.currentLocation), {headers}) 
     .toPromise() 
     .then((response) => { 
      if (response.status !== 201) { 
       this.trace.error('log','postLog',`error response: ${response.status}`); 
      } 
     }) 
     .catch(error => { 
      this.trace.error('log','postLog',`err post log:${error}`); 
     });