Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of @NgComponent map: const {} vs. class annotations

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?

like image 705
Warren Strange Avatar asked Jan 26 '14 22:01

Warren Strange


1 Answers

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.

like image 147
pavelgj Avatar answered Dec 01 '22 09:12

pavelgj