【发布时间】:2018-03-23 07:11:39
【问题描述】:
我创建了一个基本表单,它接收来自用户的值并点击一个 GET API,比如说 GET API1 并以表格格式返回数据。 这是代码:
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import { Hero } from './hero';
@Component({
selector: 'hero-form',
templateUrl: './hero-form.component.html'
})
export class HeroFormComponent {
model:any = {};
submitted = false;
data: any;
constructor(private http: Http) {}
onSubmit() {
this.submitted = true;
this.http.get(`http://localhost:8188/data/v1/Api/res/${this.model.config}/${encodeURIComponent(this.model.start)}/${encodeURIComponent(this.model.end)}`)
.subscribe(response => this.data = response.json());
}
}
现在,如果我想访问另一个 API,假设 GET API2 具有相同的参数集,那么我该怎么做呢?
编辑:在实际从表单中获取值之前可能是一个逻辑 - 喜欢在 API GET1 或 API GET2 之间进行选择,然后继续使用表单会有所帮助。
【问题讨论】: