资产目录中的Angular 7静态配置文件

时间:2019-05-20 10:34:29

标签: angular

我试图导入一些需要特定于环境的Angular配置(主要是因为我在Azure中运行该应用程序的不同实例,因此我需要在发布时而不是在构建时配置这些变量)。

为此,我在角度 TYCCustomerSupportVc * popup=[[TYCCustomerSupportVc alloc]init]; popup.fromfwd=YES; popup.ContactDictionary=[NSMutableDictionary dictionary]; NSLog(@"contact dict is %@",[GlobalClass singleton].Contactjson); popup.ContactDictionary= [GlobalClass singleton].Contactjson; popup.btntag=celltag; popup.view.frame= CGRectMake(_parentController.view.frame.origin.x+18,100 , popup.view.frame.size.width, popup.view.frame.size.height); [_parentController.view addSubview:popup.view]; [_parentController addChildViewController:popup]; [self.parentController didMoveToParentViewController:self]; //code to remove popup [self.view removeFromSuperview]; 目录中创建了一个config.json文件,并将其导入到这样的服务中

config.json

assets

env.service.provider.ts

{
  "azureAdConnectSettings": {
    "clientId": "<app-id>",
    "tenant": "<azure-tenent>",
    "redirectUri": "https://localhost:5001/signin-callback",
    "postLogoutRedirectUri": "https://localhost:5001/"
  }
}

env.service.ts

import { EnvService } from './env.service';
import configFile from '../../../assets/config.json';

export const EnvServiceFactory = () => {

  const env = new EnvService();

  const config = configFile || {};

  env.azureAdConnectSettings = config.azureAdConnectSettings;

  return env;
};

export const EnvServiceProvider = {
  provide: EnvService,
  useFactory: EnvServiceFactory,
  deps: [],
};

因此,这在开发中可以正常工作,我可以在import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class EnvService { public azureAdConnectSettings: AzureConnectSettings = null; constructor() { } } class AzureConnectSettings { clientId: string; tenant: string; redirectUri: string; postLogoutRedirectUri: string; } 中更改值,它们将被应用读取。

但是,当我使用config.json then 来构建应用程序时,更改config.json中的值(在构建的输出目录中),更改不会被接受,并且应用仍会读取预构建值。

大概是Angular正在编译配置文件。如果是这样,有没有更好的方法来实现这一目标?

0 个答案:

没有答案