php - 在environment.prod.ts 文件上设置条件

标签 php node.js angular angular-ui-router node-modules

enter image description here

如何在下面的代码和 environment.ts 文件中设置条件。

export const environment = {
  production: true,
  if(our condiion = "impdev.something.com"){
   API_url:'https://impdev.something.com/Angular',
  }
  if(our condiion = "dev.something.com"){
    API_url:'https://dev.something.com/Angular',
  }
  if(our condiion = "app.something.com"){
    API_url:'https://app.something.com/Angular',
  }

};

最佳答案

您将使用以下解决方案以其他方式实现此目的。

环境.ts

export const environment = {
  production: true,
  dev: { serviceUrl: 'https://dev.something.com' },
  stage: { serviceUrl: 'https://stage.something.com' },
  prod: { serviceUrl: 'https://prod.something.com' },
  local: { serviceUrl: 'http://localhost:8080/' },
};

NetworkService.ts

export class NetowrkService {

  url: string;
  env: string
  constructor(private http: HttpClient) {
    this.env = this.setENV();
    this.url = environment[this.env].serviceUrl;
  }

  setENV() {
    if (window.location.hostname.indexOf("dev") != -1) {
      return "dev";
    } else if (window.location.hostname.indexOf("stage") != -1) {
      return "stage";
    } else if (window.location.hostname.indexOf("localhost") != -1) {
      return "local";
    } else {
      return "prod";
    }
  }


   // Call rest API
}

关于php - 在environment.prod.ts 文件上设置条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54362003/

相关文章:

css - ionic 2 : Remove gigantic padding from form elements

javascript - 在新数组项上附加 ajax 中的 PHP 数组项

php - Socket.io、PHP、Node 和 Redis 聊天室

php - 在mysql和php中搜索两个日期

node.js - 根据请求参数 express 有条件地使用中间件

html - Angular 6 IE 样式内联

javascript - 在 Angular2 中管理不同的基本布局

php - CodeIgniter 中的 301 重定向有 ?问题

javascript - i18next 动态更改 resGetPath

node.js - 编辑 npm 库并通过热重载实时查看更改?