输入的数字将添加到API URL密钥值

问题描述 投票:1回答:1

我是Ionic,Angular和Typescript的新手,是否有可能将输入的数字作为键值之一添加到API URL中?

例如,这是我的输入html

<ion-input type="text" placeholder="Enter Number"></ion-input>

例如,这是我的API URL。

https://myapi.com/FoodDeliveryTrackingMyNumber = [输入]&userName = myuser&password = mypass

这是我的data.services.ts,用于从我的API网址中获取数据。

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class DataService {
  apiUrl = 'http://127.0.0.1:8080/https://myapi.com/FoodDeliveryTracking?MyNumber=[value from input]&userName=myuser&password=mypass';
  apiKey = ''; // <-- Enter your own key here!



    constructor(private http: HttpClient){}


    getRemoteData(){
      let headers = new HttpHeaders({'apiKey': this.apiKey});
      headers.append('Accept','application/json');
      headers.append('X-Requested-With','XMLHttpRequest');
      headers.append('content-type','application/json');
      return this.http.get(this.apiUrl, {headers: headers});
    }


}
json angular typescript api ionic-framework
1个回答
0
投票
let myParams = {'foo': 'hi there', 'bar': '???'};

let u = new URLSearchParams(myParams).toString();

console.log(u);
热门问题
推荐问题
最新问题