Javascript Angular 5外部JSON配置返回未定义
在我的资产中,我有一个带有APIRL的config.json文件Javascript Angular 5外部JSON配置返回未定义,javascript,json,angular,config,Javascript,Json,Angular,Config,在我的资产中,我有一个带有APIRL的config.json文件 { "apiUrl":"https://api.example.com" } 我有多个环境,但其中一个需要能够在构建后进行更改 import * as config from '../assets/config.json'; export const environment = { production: true, appTheme: "blue-theme", apiUrl: config.
{
"apiUrl":"https://api.example.com"
}
我有多个环境,但其中一个需要能够在构建后进行更改
import * as config from '../assets/config.json';
export const environment = {
production: true,
appTheme: "blue-theme",
apiUrl: config.apiUrl
appName: "App",
};
在我的打字中,我有
declare module "*.json" {
const value: any;
export default value;
}
执行console.log(配置)时,我得到:
但是当我执行console.log(config.apiUrl)时,我得到:
有人能告诉我我做错了什么吗?如何检索Json数据
由节点使用
const config: any = require('../assets/config.json');
export const environment = {
production: true,
appTheme: "blue-theme",
apiUrl: config.apiUrl
appName: "App",
};
使用http
请查看此处或使用其他方法
undefined
const config: any = require('../assets/config.json');
export const environment = {
production: true,
appTheme: "blue-theme",
apiUrl: config.apiUrl
appName: "App",
};