使用.NET Core JavaScriptServices构建的Angular应用程序中的环境变量

时间:2017-08-26 02:40:08

标签: angular webpack asp.net-core

我看到,与大多数SPA框架一样,Angular提供了一种将环境特定配置传递给应用程序的简便方法。我正在使用.NET Core 2.0项目搭建的Angular应用程序。我尝试使用Angular CLI环境文件和webpack DefinePlugin为我的应用程序提供环境变量。我错过了什么?

这就是我想要的:

RaycastHit2D hit = Physics2D.Raycast (transform.position, Vector2.right, ~(LayerMask.GetMask ("player")));

但是使用.NET Core JavaScriptServices。这可能吗?

1 个答案:

答案 0 :(得分:0)

环境的想法是,您可以使用NSString *sort_char = @""; //or another specific character for sorting if (sort_name != nil && sort_name.length > 0){ sort_char = [[NSString stringWithString:[sort_name substringWithRange:NSMakeRange(0, 1)]] uppercaseString]; } 每个环境,然后在environment.{ENV}.ts中定义它们的名称:

.angular-cli.json

您必须手动设置此环境文件:

在你的环境中。

...
"environments": {
  "dev": "environments/environment.ts",
  "prod": "environments/environment.prod.ts"
}
...

在您的environment.prod.ts

export const environment = {
  production: false,
  API_URL: 'http://localhost:5001'
}

然后,当您想要某些环境属性时,可以将环境对象导入.ts文件并调用它。

您正在调用的export const environment = { production: true, API_URL: 'http://www.myapi.com' } 指的是节点的环境。