Is it possible to override the built-in Angular 2 pipes so they can be used globally?

后端 未结 3 724
太阳男子
太阳男子 2021-01-11 10:49

I would like to override the \"date\" pipe and enjoy the benefit of global access everywhere just like the built-in pipe--aka, avoid having to import and use pipes[] array i

3条回答
  •  孤独总比滥情好
    2021-01-11 11:19

    Yes, use PLATFORM_PIPES in following way

    https://angular.io/docs/ts/latest/api/core/index/PLATFORM_PIPES-let.html

    import {PLATFORM_PIPES} from '@angular/core';
    import {OtherPipe} from './myPipe';
    @Component({
      selector: 'my-component',
      template: `
        {{123 | other-pipe}}
      `
    })
    export class MyComponent {
      ...
    }
    bootstrap(MyComponent, [{provide: PLATFORM_PIPES, useValue: [OtherPipe], multi:true}]);
    

提交回复
热议问题