Is it possible to override the built-in Angular 2 pipes so they can be used globally? -
i override "date" pipe , enjoy benefit of global access everywhere built-in pipe--aka, avoid having import , use pipes[] array in every component annotation. possible?
yes, can use platform_pipes add custom pipe , name pipe date hijack it.
@pipe({ name : 'date' // hijacks 'date' pipe }) class customdatepipe { transform(val, args) { return /* new value */; } } @component({ selector: 'my-app', template : '{{mydate | date}}', }) export class app { mydate = date.now(); } // provides customdatepipe globally bootstrap(app, [provide(platform_pipes, {usevalue: [customdatepipe], multi: true})]); this way won't have add specify every time in pipes property in components.
here's plnkr example working.
Comments
Post a Comment