Angular 将表单输入传递到api url

Angular 将表单输入传递到api url,angular,forms,Angular,Forms,我试图将数据从输入字段传递到api url,但似乎我做得不对。它将输入传递到api,减去表单输入。如何将输入正确地传递给api?这是我的密码: 组成部分: export class AppComponent { constructor(private http: Http) { } age = '' phone = '' sex = '' number = '' amount = '' email = '' names = '' sendDetails(){ this.http.g

我试图将数据从输入字段传递到api url,但似乎我做得不对。它将输入传递到api,减去表单输入。如何将输入正确地传递给api?这是我的密码:

组成部分:

export class AppComponent {
 constructor(private http: Http) { }
age = ''
phone = ''
sex = ''
number = ''
amount = ''
email = ''
names = ''
  sendDetails(){
    this.http.get('http://example.api.com/step1.php?'+'age=this.age&phone=this.phone&sex=this.sex&number=this.number&amount=this.amount&email=this.email&names=this.names')
    .subscribe(value => {
      const submit = value
      console.log(submit);

    })

  }
}
HTML

<input type="text" [(ngModel)]=age >
<input type="text" [(ngModel)]=phone >
<input type="text" [(ngModel)]=sex >
<input type="text" [(ngModel)]=number >
<input type="text" [(ngModel)]=amount >
<input type="text" [(ngModel)]=email >
<input type="text" [(ngModel)]=names >
<button (click)=sendDetails()> submit</button>

提交
交换:

'http://example.api.com/step1.php?'+'age=this.age&phone=this.phone&sex=this.sex&number=this.number&amount=this.amount&email=this.email&names=this.names'
用于:


这是一个非常干净的方法,在需要连接值时易于使用。

您传递的正是字符串“This.name”等。。。 如果API正常,则需要编写
+this.yourParameter+
即:


this.http.get('http://example.api.com/step1.php?age=“+this.age+'&phone='+this.phone+'&sex='+this.sex+'&number='+this.number+'&amount='+this.amount+'&email='+this.email+'&names='+this.names)

这里没有任何插值,您实际上是在传递例如
“this.name”
作为
age
的查询参数。这不一定是个问题,但您显示的内容毫无意义。给出一个真实的例子,说明你所拥有的具体问题。API真的希望所有东西都作为查询参数吗?@jornsharpe,如我所说。我不知道如何直接从输入字段向url传递参数如果没有关于接收请求的服务器的更多信息,您的问题将无法回答;它需要查询参数吗?JSON?URL编码的表单正文?“将参数传递到URL”并不是唯一的方法,也不清楚您停留在哪个特定部分。你是否真的提出了要求?你得到答复了吗?如果有错误,从哪里来,他们说什么?
`http://example.api.com/step1.php?age=${this.age}&phone=${this.phone}&sex=${this.sex}&number=${this.number}&amount={this.amount}&email=${this.email}&names=${this.names}`