1

I am trying to use enum as parameter the following way:

<div> {{ myValue | myPipe: MyEnum.ENUM_VAL }} </div>

In controller I have defined MyEnum:

@Component({
  selector: 'app-my-component',
  templateUrl: './my.component.html',
  styleUrls: ['./my.component.css']
 })
 export class MyComponent implements OnInit {

      MyEnum: MyEnum;

       ....
  }

I am getting: TypeError: Cannot read property 'ENUM_VAL' of undefined

What is the proper way of using it?

Onorio Catenacci
  • 14,928
  • 14
  • 81
  • 132
Tomas Marik
  • 4,053
  • 3
  • 31
  • 62

1 Answers1

1

You are declaring MyEnum, but it is not a definition. You would have to initialize it (as @developer033 said).

For reference: Javascript variable definition declaration

So give your enum a initial value and it should work, although I have not used an enum in a pipe, you could work around it by placing the enum in your pipe class and sending an argument that tells your pipe to use the enum.

Community
  • 1
  • 1
Pezetter
  • 2,783
  • 2
  • 22
  • 40