Follow the example.
The JSON file:
_config.json
{
"devpg": {
"username": "johndoe",
"password": "secret",
"database": "mydb",
"host": "127.0.0.1",
"dialect": "postgres",
"port": "5432",
"url": "postgres://johndoe:secret@127.0.0.1:5432/mydb"
},
"prodpg": {
"username": "server1",
"password": "secret",
"database": "mydb",
"host": "localhost",
"dialect": "postgres",
"port": "5432",
"url": "postgres://server1:secret@localhost:5432/mydb"
},
"sessionKey": "alfja1234",
}
The component.ts file
import { Component, OnInit } from '@angular/core';
const _config = require('../../_config/_config.json');
@Component({
selector: 'app-config03',
templateUrl: './config03.component.html',
styleUrls: ['./config03.component.scss']
})
export class Config03Component implements OnInit {
config: any;
constructor() { }
ngOnInit(): void {
let json = JSON.stringify(_config);
this.config = JSON.parse(json);
this.setenv();
}
}
Brazilian system analyst graduated by UNESA (University Estácio de Sá – Rio de Janeiro). Geek by heart.