相关疑难解决方法(0)

Angular 2 - 动态查找要在http请求(服务)中使用的基本URL

我想知道是否有一种动态的方式来获取基本网址,以便在http请求中使用?

有没有办法动态获取http://192.123.24.2:8080

public getAllTickets() {
    this._http.get('http://192.123.24.2:8080/services/', {
        method: 'GET',
        headers: new Headers([
            'Accept', 'application/json',
            'Content-Type', 'application/json'
        ])
    })
Run Code Online (Sandbox Code Playgroud)

所以,我的请求看起来像:

public getAvailableVersions() {
    this._http.get('../services', {
        method: 'GET',
        headers: new Headers([
            'Accept', 'application/json',
            'Content-Type', 'application/json'
        ])
    })  
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种不必硬编码REST调用URL的方法.或者是具有URL的全局变量的唯一选择?

谢谢!

rest url service http angular

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

http ×1

rest ×1

service ×1

url ×1