Dynamic pipe in Angular 2

后端 未结 6 1001
失恋的感觉
失恋的感觉 2020-12-01 12:35

I\'m trying to create a component where you can pass which pipe that should be used for a list inside the component. From what I could find by testing and looking around for

6条回答
  •  醉酒成梦
    2020-12-01 13:06

    Unfortunately I don't think so. It's the same as in angular1 where you have a function return a string for the dynamic Pipe you want.

    Looking at the docs that's exactly how they show it as well.

    https://angular.io/docs/ts/latest/guide/pipes.html

    template: `
       

    The hero's birthday is {{ birthday | date:format }}

    `

    Then in the controller:

    get format()   { return this.toggle ? 'shortDate' : 'fullDate'}
    

    Alas, it could be worse! :)

提交回复
热议问题