如果响应成功,如何在GET之后调用http POST服务调用。
我按以下方式编写了GET调用,
...
POST的示例网址:
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);
}
}
答案 0 :(得分: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
}