简体   繁体   English

如何在 Angular 中动态更改环境变量?

[英]How dynamically change environment variable in Angular?

I am trying to change environment variable when I am inserting custom URL in text box and that will be change in Environment Variable on the basis of that am showing response on website.当我在文本框中插入自定义 URL 时,我试图更改环境变量,这将在环境变量中更改,因为我在网站上显示响应。

Here is my TypeScript code:这是我的打字稿代码:

   generateQRCode() {
      this.value = this.qrcodename;
      localStorage.clear()
      localStorage.setItem("key", JSON.stringify(this.qrcodename));

  }

HTML HTML

  <div class="form-group">
      <input
        type="text"
        class="form-control"
        id="qr"
        aria-describedby="qr"
        placeholder="Enter code"
        required
        [(ngModel)]="qrcodename"
      />
    </div>

and i want to change at this baseUrl with value of qrcodename我想在这个 baseUrl 上更改 qrcodename 的值

export const environment = {
  production: false
   baseUrl: "http://127.0.0.1:5000/"

};

I just do with local storage and access it on where i want to use this Url input here is my simple code我只是使用本地存储并在我想使用此 Url 输入的地方访问它,这是我的简单代码

  getDashboardData(): Observable<any> {

    let url = JSON.parse(localStorage.getItem('key'));
    return this.http.get(url + "/dashboard");

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM