@3go/environment 中文文档教程

发布于 6年前 浏览 24 项目主页 更新于 3年前

@3go/environment

Install

$ yarn add @3go/environment

$ npm i @3go/environment --save

How to

适用于角度 5 和 6。

Demos

角度 5:

https

://stackblitz.com/edit/3go-environment-angular5角度 6:

  • Dependencies to work: rxjs-compat .

https:

import:

//stackblitz.com/edit/3go-environment-angular6 app.module.ts

@NgModule({
  imports: [
    (...)
    GoEnvironmentModule.forRoot({
      name: "params",
      environments: {
        "localhost": "localhost",
        "prod": "api.myapp.com"
        }
      })
  ],

ConfigFile: Default values

名称:“配置”, 扩展名:“json”, 路径:“./资产/”, environments: { "localhost": "localhost" }

app.component.ts

export class AppComponent implements OnInit {
  constructor(private envService: GoEnvironmentService) {}

  ngOnInit(): void {
    this.envService.config().then(
      () => this.envService.replace(environment)
    );
  }
}

创建一个与您的配置同名的 json 文件。

参数.json

{
  "localhost": {
    "url": "some value here",
    "api": "some value here"
  },
  "prod": {
    "url": "some value here",
    "api": "some value here"
  }
}

Use native environment

{{ environment.url }}
{{ environment.api }}

@3go/environment

Install

$ yarn add @3go/environment

or

$ npm i @3go/environment --save

How to

Works with angular 5 and 6.

Demos

Angular 5:

https://stackblitz.com/edit/3go-environment-angular5

Angular 6:

  • Dependencies to work: rxjs-compat .

https://stackblitz.com/edit/3go-environment-angular6

import:

app.module.ts

@NgModule({
  imports: [
    (...)
    GoEnvironmentModule.forRoot({
      name: "params",
      environments: {
        "localhost": "localhost",
        "prod": "api.myapp.com"
        }
      })
  ],

ConfigFile: Default values

name: "config", extension: "json", path: "./assets/", environments: { "localhost": "localhost" }

app.component.ts

export class AppComponent implements OnInit {
  constructor(private envService: GoEnvironmentService) {}

  ngOnInit(): void {
    this.envService.config().then(
      () => this.envService.replace(environment)
    );
  }
}

create a json file with a same name of your config.

params.json

{
  "localhost": {
    "url": "some value here",
    "api": "some value here"
  },
  "prod": {
    "url": "some value here",
    "api": "some value here"
  }
}

Use native environment

{{ environment.url }}
{{ environment.api }}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文