Angular: Storing long text without a database

Viewed 307

Sorry if the question is wrong I'm a beginner.. I'm working on an educational website using Angular 11 that includes articles (around 20 articles). However those articles are generally static and won't change later. I made a component as a template for the articles so that I send the texts to them as input, but I felt like there maybe a more efficient way to do it.. is there a way to store and read them as resources? Or shall I just store them as constants? Any ideas of how to do this properly? Do I really need to make a database for this context?

<div class="article-block">
<table class="articleBody">
    
<tr>
    <td><app-item-navigator></app-item-navigator></td>
    <td width="95%">
        <div class="articleText">
{{
    // text is supposed to be here
}}
        </div>
    </td>
    
</tr>
</table>
</div>
1 Answers

Its a good practise to keep separation of concerns. F.ex. keep all articles in same place. Usually to store application state, stores are used (like services). But thats for state, which tends to keep changing. For your case, since articles are static, simply create another file and store there as constants. Egzample:

articles.ts:

export const article1 = "lorem Ipsum ...";
export const article2 = "Dolar sit ...";

Then in your component simply import it:

import { article1, article2 } from './articles';

And if you use them directly in the template, need to grab a reference of articles in component class, f.ex:

export class MyComponent  {
  article1 = article1;

Thats the most simple way I can suggest. Also for import / exporting - tried to keep it simple here.

Related