我基本上尝试在 appSettings 中设置 API URL 路径,以便我可以轻松地在生产和开发环境中来回更改。
这是我的 appSettings.json 文件。apiURL 是我试图设置和获取的变量。
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"apiURL": "http://10.241.2.68:8132/api"
}
Run Code Online (Sandbox Code Playgroud)
这是我的页面,它尝试访问我在 appSettings.json 中设置的环境变量。
import { Injectable } from '@angular/core';
// import { Defendant } from 'src/app/Models/Defendant';
import { Charge } from 'src/app/Models/Charge';
import { DefendantItem } from '../Models/DefendantItem';
import { Defendant_Charge } from '../Models/Defendant_Charge';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { AppConfiguration } from "read-appsettings-json"; …Run Code Online (Sandbox Code Playgroud)