Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Additional resource reference in the angular component

Tags:

angular

For example, we have a file with localized strings

{
  "title": "Example title",
  "description": "Some text"
}

Let's assume we also have a component with some custom decorator @I18n()

@Component({ ... })
@I18n('./my-translations.json')
export class MyAngularComponent {

}

And template

<h2>{{ i18n.title }}</h2>
<p>{{ i18n.description }}</p>

Is it possible to include one more external resource (besides templateUrl and styleUrls) into the component?

like image 966
Taras Hupalo Avatar asked Aug 13 '18 11:08

Taras Hupalo


1 Answers

You could extend Component decorator however i would not do that, since it may have undesired effects on compiler and depends on Component changes between angular versions. I would rather allow multiple arguments/variable arguments/array parameter in I18n decoroator or allow multiple I18n decorators, it means that I18n decorator should check for class modifications done by previous decorators and append its data accordingly.

like image 93
kemsky Avatar answered Nov 20 '22 06:11

kemsky