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!
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;
}
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 {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With