6

can someone tell me if and how it is possible to use Dart enums in angular2 view templates?

It's suggested in Typescript to copy the enum into a component-scope. This works because an enum in javascript is a simple instance variable with a prototype.

But since enums in dart are first class citizens, they cannot be moved to an instance variable.

Thanks in advance!

Benjamin Jesuiter
  • 1,122
  • 1
  • 13
  • 24

2 Answers2

11

We're working on bringing formal support, but you can always add a getter for now:

enum MyEnum {
  stateA,
  stateB,
}

class MyComponent {
  MyEnum get stateA => MyEnum.stateA;
}
matanlurey
  • 8,096
  • 3
  • 38
  • 46
4

Use the exports property of your Component class. Copied from here in the AngularDart Guide.

enum MyEnum { foo, bar, baz }

@Component(
  selector: 'example',
  exports: const [MyEnum],
  template: '<p>{{MyEnum.bar}}</p>',
)
class Example {}
Ryan Haining
  • 35,360
  • 15
  • 114
  • 174
Luke Hanks
  • 179
  • 1
  • 5
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Rot-man Apr 11 '19 at 21:19