使用angular 2在同一函数中同时调用GET和POST服务调用 [英] calling both GET and POST service calls in same function using angular 2

查看:73
本文介绍了使用angular 2在同一函数中同时调用GET和POST服务调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果响应成功,如何在GET之后拨打http POST服务电话.

How do i call http POST service call after the GET, if response is success.

我以以下方式编写了GET调用,

I have the written the GET call in the following way,

import {Page, NavController} from 'ionic-angular';
import {Http, Headers} from 'angular2/http';
import 'rxjs/Rx';

@Page({
  templateUrl: 'build/pages/login/login.html'
})


export class LoginPage {    
  constructor(private nav: NavController, public http: Http) {
  }

  onLogin(value: string): void { 
    if(this.authForm.valid) {        
      this.http.get('https://itunes.apple.com/us/rss/topmovies/limit=1/json')
      .map(res => res.json())
      .subscribe(
        data => {console.log(JSON.stringify(data));},
        err => this.logError(err),
        () => console.log('Random Quote Complete')
      );

      this.nav.push(AccountViewPage);
    }
  } 

  logError(err) {
    console.error('There was an error: ' + err);
  }
}

POST的示例网址:

sample url for POST:

https://itunes.apple.com/1/json

headers: {"Content-Type": "application/x-www-form-urlencoded" },
ignoreAuthModule: 'ignoreAuthModule'

推荐答案

 **It could be better if you use another Function sucees**  

  onLogin(value: string): void { 
   if(this.authForm.valid) {        
     this.http.get('https://itunes.apple.com/us/rss/topmovies/limit=1/json')
     .map(res => res.json())
      .subscribe(
       data => {console.log(JSON.stringify(data));},
       err => this.logError(err),
       () => this.add();
      );

     this.nav.push(AccountViewPage);
  }
  } 

  public add(): void {
  // another service here
  }

这篇关于使用angular 2在同一函数中同时调用GET和POST服务调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆