简体   繁体   English

如何使用angular4从appsettings.json到打字稿文件中读取键值

[英]How to read key values from appsettings.json to typescript file using angular4

How to read key values from appsettings.json to typescript file using angular4 如何使用angular4从appsettings.json到打字稿文件中读取键值

{
  "Logging": {
    "IncludeScopes": false,
    "Debug": {
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "Console": {
      "LogLevel": {
        "Default": "Warning"
      }
    }
  },
  "Application": {
    "ServiceUrl": "http://localhost:12345",
    "BaseURL": ""
  },

Depending on where this JSON file is located in your Web application, you would be able to use Angular's Http client to do a GET request and fetch it's data. 根据此JSON文件在Web应用程序中的位置,您将能够使用Angular的Http客户端执行GET请求并获取其数据。 You can even add a typescript interface to expect a result. 您甚至可以添加一个打字稿界面以期望得到结果。 A bit like this: 有点像这样:

import { Observable } from 'rxjs/Observable';
import { HttpClient } from '@angular/common/http';

export interface someInterface {
   foo: string,
   bar: number
}

export class SomeClass {
  constructor(private http: HttpClient) { }
  data: someInterface;

  someFunc(){
    this.http.get<someInterface>('/path/to/json').subscribe(result => {
       this.data = result;
    });
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Angular 10 中读取 appsettings.json 文件配置 - How to read appsettings.json file configuration in Angular 10 如何从 appsettings.json 读取列表并将其绑定到 mvc dropdownlistfor() - How to read a list from appsettings.json and bind it in the mvc dropdownlistfor() 以字符串形式读取整个 appsettings.json 文件 - Read whole appsettings.json file as a string 如何使用 .Net 核心控制台应用程序从 appsettings.json 读取部分? - How to read a section from appsettings.json using .Net core console application? 如何在appSettings.json中读取字符串数组? - How to read a string array in appSettings.json? 如何从 .Net 6 中的 appsettings.json 文件中获取数组? - How to get an array from appsettings.json file in .Net 6? C# CommandLineApplication 控制台应用程序读取一个appsettings.json文件 - C# CommandLineApplication Console App to read an appsettings.json file .Net Core Cant从appsettings.json中读取连接字符串 - .Net Core Cant read connection string from appsettings.json Serilog.Sinks.Postgresql:从 appsettings.json 读取配置 - Serilog.Sinks.Postgresql: Read configuration from appsettings.json 如何在同一appsettings.json中引用另一个键 - How to refer to another key in the same appsettings.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM