In my Angular 7 multi-module application, I have a utility namespace structured as follows:
export namespace Utils {
export function util1 (arg: type) {
}
export function util2 (arg: type) {
}
...
}
Some of these functions are used in templates while others are not.
After conducting research, I discovered that the recommended method for exposing these methods for template use is by utilizing services. However, I am unsure how to do this without individually wrapping each function within a service, which I find unsatisfactory.
What would be the appropriate approach in this situation?
Update
Below is an example of a utility function I utilize within templates (specifically for resetting the first record of a p-table
and applying the filter):
function filter(table, value, field, filterMatchMode): void {
table.first = 0;
table.filter(value, field, filterMatchMode);
}
Used in the template:
<input *ngSwitchCase="'name'" pInputText type="text" (input)="utils.filter(table, $event.target.value, col.field, col.filterMatchMode)">