5

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?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Warren Strange
  • 745
  • 5
  • 12

2 Answers2

5

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.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
pavelgj
  • 2,246
  • 11
  • 13
  • 1
    What does "=>!" mean? My first guest would have been to negate the value before assigning it, but this doesn't make sense for a String. [[Edit]] Oups, just saw Seth's [question](http://stackoverflow.com/questions/21422743/what-is-the-equivalent-annotation-for-the-old-map-attr-in-angulardart) ... which answers my question :). – Patrice Chalin Jan 29 '14 at 12:49
1

FYI, There is now a PR pending for adding support for inheritance, check "Add support for inheritance in Directives and Components"

vicb
  • 144
  • 5