Reputation: 785
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?
Upvotes: 5
Views: 370
Reputation: 2701
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.
Upvotes: 5
Reputation: 144
FYI, There is now a PR pending for adding support for inheritance, check "Add support for inheritance in Directives and Components"
Upvotes: 1