[英]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.