#PipeTransform ENUM

1 messages · Page 1 of 1 (latest)

elder gulch
#

I'm not sure to understand what you want to achieve. But technically, you can use your Pipe in your component.

#

But it's always better to use it directly in the view

#

How about <p>{{ item | taskType }}</p> ?

#

Your pipe is probably wrong

#

Remove some complexity to isolate the problem

@Pipe({
  name: 'taskType',
})
export class TaskTypePipe implements PipeTransform {
  constructor() {}

  transform(type: TaskType): string {
    switch (type) {
      case TaskType.BMW:
        return `Test BMW`;
      case TaskType.MERCEDES:
        return `Test Mercedes`;
      case TaskType.VOLVO:
        return `Test Volvo`;
      default:
        return 'Unknown task type';
    }
  }
}
#
public getEnumKeys(): string[] {
  return Object.keys(TaskType);
}
#

Put a break point in the switch of your pipe to see what happens

#

Have you added the pipe to your view?
<p>{{ item | taskType }}</p>

#

How about the break point?

#

Try to make a Stackblitz cause it's hard to tell without the full context

strong igloo
#

@pale pecan electrochip asked you twice to use the pipe in the template, but there is no pipe used in your Stackblitz example.

elder gulch
strong igloo
#

That's already done from the beginning for me.
If you expect something else, take more time to explain your expectations.