invoke pipe during run time using pipe name /metadata

后端 未结 2 1555
花落未央
花落未央 2020-12-09 22:33

I\'m trying to build a dynamic table where i wand to decide in run time which pipe to use (If Any).

I\'m trying to achieve something similar to (Sim

2条回答
  •  爱一瞬间的悲伤
    2020-12-09 23:22

    You can't apply pipes dynamically. What you can do is to build a "meta" pipe that decides what transformation(s) to do.

    @Pipe({
      name: 'meta'
    })
    class MetaPipe implements PipeTransform {
      transform(val, pipes:any[]) {
        var result = val;
        for(var pipe of pipes) {
          result = pipe.transform(result);
        }
        return result;
      }
    }
    

    and then use it like

    {{cell.content | meta:[cell.pipe]}}
    

提交回复
热议问题