I see some Angular dart samples specify the attribute binding using this form:
@NgComponent(
selector: 'foobar',
publishAs: 'foo',
map : const { "label" : "@label"}
)
While others annotate individual fields:
class FooBar {
@NgOneWayOneTime("label")
String label;
}
Is there a reason I would want to use one form vs. the other?
And a follow on question: Can I mix and match the two forms?
Let's say I have a base class:
MyBase {
@NgOneWay("label")
String label;
}
Can I inherit from that base class, and have Angular pick up the annotation?
I believe it's recommended that you use annotations as they are much more readable.
There are some use-cases when you might want to use the old-style map, for example, reusing the class for multiple components/directives/controllers:
@NgComponent(selector: 'foo', map: const {'attr-a': '=>attrA'})
@NgComponent(selector: 'bar', map: const {'attr-a': '=>!attrA'})
class FooBarComponent {
String attrA;
}
As you can see, you can define different mappings but use the same class. In theory this should rarely be needed, but if needed it's available.
Neither forms currently support inheritance. Please file a feature request if you feel strongly about it.
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