在我的资产中,我有一个带有apiurl
的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
appName: "App",
};
在我的打字中,我有我有
declare module "*.json" {
const value: any;
export default value;
}
当我做console.log(config(时,我得到:
{
apiUrl:"https://api.example.com"
}
但是当我做console.log(config.apiurl(时,我会得到:
undefined
有人可以给我打电话我做错了什么?
如何检索JSON数据
使用node
const config: any = require('../assets/config.json');
export const environment = {
production: true,
appTheme: "blue-theme",
apiUrl: config.apiUrl
appName: "App",
};
使用http
如何正确地从http中提取JSON数据?
在Angular 2中获取如何在Angular 2中获取JSON文件