I\'m trying to build \'utility\' services (classes) for an angular project. The utility classes have static functions (so we don\'t have to instantiate needless objects).
There is already a pattern for doing this in Angular called pipes
. In Angular 1 this was called filters
.
In Angular you create your custom pipe class and use the |
in the template to pass values to. There is a built in one for dates, it is used like:
{{ "2017-01-24" | date }}
Of course if this pipe does not do what you want, you can create your own:
@Pipe({
name: 'myDate'
})
export class MyDate implements PipeTransform {
transform(value: string): string {
return new Date(value);
}
}
For more info please see: https://angular.io/docs/ts/latest/guide/pipes.html