Skip to content
Advertisement

Angular – How to link several typescript files with one template file?

Imagine if you have a typescript file like the following one:

JavaScript

I would like to outsource these methods. However, the classes must inherit the properties from ProductAlertsComponent, as it would operate on/with them. So, in a separate file, I would do the following logic:

JavaScript

But the template angular file (product-alerts.component.html) would not recognize calculatesAge() and checkIdPermission(). How could I solve it? It is not maintainable to have a ProductAlertsComponent class with several methods that could grow after years of developing. How could I link the extended class with the template angular file?

Advertisement

Answer

Notice that the template is defined in the @Component decorator, not in the class itself. Therefore reusing the template is as simple as

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement