Angular 8 - 从 'ng serve..' 获取配置参数 (Ej. --configuration)
Angular 8 - Get config parameters from 'ng serve..' (Ej. --configuration)
我在 运行 Angular Ej 时试图从配置参数中获取值。 =>
node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng s -c custom-value
我需要从命令中获取这些 'custom-value' 并在应用程序启动之前使用它们(可能在 main.ts 文件中)
if (environment.production) {
enableProdMode();
}
if (configValue === 'custom-value') {
/** Do something special*/
}
有什么办法吗?
非常感谢!
如果你想要一个配置参数,这应该是 environment.ts
文件的一部分。
创建自定义 environment-file,并 link 在 angular.json
文件中创建新的“配置”。
如果您将您的配置命名为“bob”,您就可以为您的应用程序提供服务(出于开发目的:
ng serve -c bob
或构建为:
ng build -c bob
但是无法输入“其中一个”配置属性,它是您要切换的整个 environment.ts
文件。
当然,自 environment.ts
文件以来,您可以轻松地将 TypeScript 对象合并在一起(查看 Object.assign
或 ES2015 展开运算符)。
有关 angular.json
文件的其他文档,请参阅此处的文档:
https://angular.io/guide/workspace-config
我在 运行 Angular Ej 时试图从配置参数中获取值。 =>
node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng s -c custom-value
我需要从命令中获取这些 'custom-value' 并在应用程序启动之前使用它们(可能在 main.ts 文件中)
if (environment.production) {
enableProdMode();
}
if (configValue === 'custom-value') {
/** Do something special*/
}
有什么办法吗? 非常感谢!
如果你想要一个配置参数,这应该是 environment.ts
文件的一部分。
创建自定义 environment-file,并 link 在 angular.json
文件中创建新的“配置”。
如果您将您的配置命名为“bob”,您就可以为您的应用程序提供服务(出于开发目的:
ng serve -c bob
或构建为:
ng build -c bob
但是无法输入“其中一个”配置属性,它是您要切换的整个 environment.ts
文件。
当然,自 environment.ts
文件以来,您可以轻松地将 TypeScript 对象合并在一起(查看 Object.assign
或 ES2015 展开运算符)。
有关 angular.json
文件的其他文档,请参阅此处的文档:
https://angular.io/guide/workspace-config