Member-only story
The Fastest Way To Build Lightweight Angular Content Service
The best solutions are simple!

In the typical Angular applications, we use a lot of titles, labels, headers, and more content. But if you need a way to put those content elements in one place, you need something like a dictionary. It’s a combination of small words and more extensive sentences.
Some applications need multiple languages, but others need one language but have loads of content to re-use. In this article, I want to show you the fastest way to create a ContentService
(some call it a dictionary) for your Angular application.
If you need a content service with multiple languages, I highly recommend NGX-Translate. This package offers a simple API and Pipe mechanism to re-use pieces of content but also supports multiple languages.
Create a Content Service
The simplest and fastest way to create Angular Services is by using the Angular CLI.
ng generate service services/content
By running this command, you will generate an Angular Service, automatically added to the app.module.ts
file. If your project has different settings for the CLI, it could appear in another Angular Module.
Now the Content Service looks like this.
Create a JSON Dictionary File
You need to create a dictionary file to put in all your titles, labels, and other content. Please put it in a place that works best for your application.
I create a dictionary
folder where I make the general.dictionary.json
file, but I can have more dictionary files there.
The content I put in there looks like this.