npm i @deejayy/reactive-config
export class ConfigVars {
public apiUrl!: string;
}
imports: [
...
ReactiveConfigModule.forRoot(ConfigVars, { configPath: '/assets/config-new.json' }),
],
/assets/config-new.json:
{
"apiUrl": "http://localhost"
}
Static variable: {{ apiUrl }}
Reactive variable: {{ apiUrl$ | async }}
public apiUrl: string = this.config.get('apiUrl'); // gets the latest value statically
public apiUrl$: Observable<string> = this.config.getStream('apiUrl'); // get values reactively with streams
constructor (private config: ReactiveConfigService<ConfigVars>) {}
<button (click)="updateVar()">change</button>
public updateVar() {
this.config.set('apiUrl', 'new value');
}