Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对environment.prod.ts文件设置条件_Php_Node.js_Angular_Angular Ui Router_Node Modules - Fatal编程技术网

Php 对environment.prod.ts文件设置条件

Php 对environment.prod.ts文件设置条件,php,node.js,angular,angular-ui-router,node-modules,Php,Node.js,Angular,Angular Ui Router,Node Modules,如何在下面的代码和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.som

如何在下面的代码和
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',
  }

};

这里可以使用三元运算符

export const environment = {
  production: true,
  API_url: your_condition_here ? '' : '';
};

但是从哪里得到条件呢?

可以在这里使用三元运算符

export const environment = {
  production: true,
  API_url: your_condition_here ? '' : '';
};
但是从何处获得条件?

Main.ts

if (environment.production) {
  enableProdMode();
}
环境科技

export const environment = {
  production: false,
  animal: 'idk if it's what you want, but in 
angular.json
ctrl + f to search for
fileReplacements
, in here you can tell Angular which environment folder file to replace with which under the different modes.. then you can access the same variable in
environment.ts
though your whole app, and it will be replaced automatically depending on your serve or build setups.

if unsure, just copy-paste the whole "production" JSON tha tcointains the
fileReplacements
property, and change the
replace
value with a new environment.ts file that you created (as in
environment.dev.ts
) and then copy all the variables from one environment to another and change values, and use them through the app

You will achieve this in other way using following solution.

environment.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/' },
};
导出常量环境={
制作:假,,
动物:'Main.ts

if (environment.production) {
  enableProdMode();
}
环境科技

export const environment = {
  production: false,
  animal: 'idk if it's what you want, but in 
angular.json
ctrl + f to search for
fileReplacements
, in here you can tell Angular which environment folder file to replace with which under the different modes.. then you can access the same variable in
environment.ts
though your whole app, and it will be replaced automatically depending on your serve or build setups.

if unsure, just copy-paste the whole "production" JSON tha tcointains the
fileReplacements
property, and change the
replace
value with a new environment.ts file that you created (as in
environment.dev.ts
) and then copy all the variables from one environment to another and change values, and use them through the app

You will achieve this in other way using following solution.

environment.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/' },
};
导出常量环境={
制作:假,,

animal:“idk,如果你想要的话,但是在
angular.json
ctrl+f中搜索
fileReplacements
,在这里你可以告诉angular在不同模式下替换哪个环境文件夹文件。然后你可以在
environment.ts
中访问整个应用程序中的同一变量,它将被替换d根据您的服务或构建设置自动生成


如果不确定,只需复制粘贴包含
fileReplacements
属性的整个“生产”JSON,并使用您创建的新environment.ts文件更改
replace
值(如
environment.dev.ts
)然后将所有变量从一个环境复制到另一个环境并更改值,如果需要,通过应用程序idk使用它们,但在
angular.json
ctrl+f中搜索
fileReplacements
,在这里您可以告诉angular在不同模式下要替换哪个环境文件夹文件..然后您可以通过整个应用程序在
environment.ts
中访问相同的变量,并且该变量将根据您的服务或构建设置自动替换


如果不确定,只需复制粘贴包含
fileReplacements
属性的整个“生产”JSON,并使用您创建的新environment.ts文件更改
replace
值(如
environment.dev.ts
)然后将所有变量从一个环境复制到另一个环境并更改值,然后通过应用程序使用这些变量。您将使用以下解决方案以其他方式实现这一点

环境。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
}
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
}

您将使用以下解决方案以其他方式实现这一点

环境。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
}
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
}

您不能在environment.ts文件中添加条件,但在服务中您可以创建决定environment Tok、@TheParam的函数,但最好的方法是什么。因为我有3个环境,我添加了解决此问题的最佳方法。您不能在environment.ts文件中添加条件,但在服务中您可以创建乐趣这是我的问题,当你检查这些条件时,如何获得条件?意思是解释一下你的流程意思是在这页上条件的可能性这是我的问题问题:当你检查这些条件时,如何在这里获得条件?意味着解释一点你的流程意味着此页面上条件的可能性是可行的,但是,是否有任何可能的共同用途,因为在这个项目中,我们添加了大约10-12个服务文件。创建一个父服务类并在所有12个服务中继承它。那这就是我们正在做的。没有办法在objectyes中添加条件。是的,它工作正常,但是,在这个项目中,我们添加了大约10-12个服务文件,有没有可能共同使用它。创建一个父服务类并在所有12个服务中继承它。这就是我们正在做的。没有办法在object中添加条件