I need to create global dictionary with translations in Angular and I want to use this dictionary in each component. I have created a custom service:
import { Injectable } from "@angular/core";
import _dictionary from "../assets/js/dictionary.json";
interface IWords {
[key: string]: string;
}
@Injectable({
providedIn: "root"
})
export class DictionaryService {
private dictionary = new Map<string, IWords>();
constructor() {
console.log(_dictionary);
}
}
Then I have added this to providers: @NgModule({ providers: [
DictionaryService ]});
As you can see, service uses json file with translations.
Problem is that constructor of service does not work, so I can not see message:
console.log(_dictionary);
@Injectable({ providedIn: "root" })