2016-05-18 3 views
0

Wie rufe ich HTTP POST-Service-Aufruf nach dem GET, wenn die Antwort erfolgreich ist.Aufruf von GET und POST-Serviceaufrufen in der gleichen Funktion mit Winkel 2

Ich habe die die GET-Aufruf in der folgenden Art und Weise geschrieben,

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); 
    } 
} 

Beispiel-URL für POST:

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

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

nicht tun kann Post im Abonnenten? –

Antwort

1
**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 
    } 
+0

Danke @ mayur..das ist, was ich erwartet..Aber es wird keine zweite Funktion ausführen, bis die erste Antwort richtig kommt? – vishnu

+0

Sie können nach Daten die add() oder danach() => wie Abhängigkeit nach dem Erfolg – mayur

+0

Dank @ mayur..one mehr ich bekomme Fehler beim Übergeben von Parametern zu GET Anruf erhalten; Argument vom Typ '{params: URLSearchParams; } 'kann nicht dem Parameter' RequestOptionsArgs 'zugewiesen werden. Dies ist mein Code: let options = new RequestOptions ({ params: new URLSearchParams ('validateUsr = false') }); – vishnu

Verwandte Themen