如何访问TypeScript文件中的Azure Web App应用程序设置值 [英] how to access the azure web app application setting values in to typescript file

查看:77
本文介绍了如何访问TypeScript文件中的Azure Web App应用程序设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Visual Studio 2015开发了angular 2应用程序.然后,将我的angular2 Web应用程序发布到azure Web应用程序中后,一切正常,但是我无法将azure Web应用程序设置值输入到我的Typescript文件中. angular 2网络应用.

I had developed angular 2 application using visual studio 2015. then after I have published my angular2 web app into azure web app it's working everything fine but I am not able to get the azure web app application setting values into my typescript file of angular 2 web app.

能否请您分享如何在任何打字稿文件中访问azure Web应用程序应用程序设置值.

Can you please share how to access the azure web app application setting values in to any typescript file.

-Pradeep

推荐答案

最后,我将上述问题解决为访问打字稿文件中的Azure Web应用程序应用程序设置值".

Finally, I resolved the above issue as "to access the azure web app application setting values in to typescript file."

我在 Index.cshtml 中编写了以下代码行,用于访问 web.config 文件中的应用设置值.

I wrote the below lines of code in Index.cshtml for accessing the app setting values from web.config file.

    <script>
    window.config = {
        apiBaseUrl: '@System.Configuration.ConfigurationManager.AppSettings["ApiBaseUrl"]',

    };
</script>

此后,我在 Services.ts

import {Injectable, Inject, Optional, OpaqueToken} from '@angular/core';
export const API_BASE_URL = new OpaqueToken('API_BASE_URL');

@Injectable()
export class ApplicationClient {
private baseUrl: string = undefined; 

constructor(@Optional() @Inject(API_BASE_URL) baseUrl?: string) {
    this.baseUrl = baseUrl ? baseUrl : ""; 
  }
}

接下来,我编写了以下代码行 app.module.ts

Next I have wrote the below lines of code app.module.ts

import { ApplicationClient,API_BASE_URL } from './shared/Services';
providers: [ { provide: API_BASE_URL, useValue: window['config']['apiBaseUrl'] }]

此后,您需要访问设置值的任何地方,只需在打字稿文件中导入 Services.ts 文件的路径,就像下面的代码行一样.

After that where ever you need to access the setting value, just import the path for Services.ts file in your typescript file like this below lines of code.

import { API_BASE_URL } from '../shared/Services';
 @Injectable()
export class writingService {
private _AppUrl = API_BASE_URL+'api/myApplication/';
}

-Pradeep

这篇关于如何访问TypeScript文件中的Azure Web App应用程序设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆