使用@NgComponent map:const {}与class annotations

War*_*nge 5 dart angular-dart

我看到一些Angular dart样本使用以下形式指定属性绑定:

@NgComponent(
  selector: 'foobar',
  publishAs: 'foo',
  map : const { "label" : "@label"}
)
Run Code Online (Sandbox Code Playgroud)

其他人注释个别字段:

class FooBar {
  @NgOneWayOneTime("label")
  String label;
 }
Run Code Online (Sandbox Code Playgroud)

我有理由想要使用一种形式而不是另一种吗?

还有一个问题:我可以混合搭配这两种形式吗?

假设我有一个基类:

MyBase {
   @NgOneWay("label")
   String label; 
}
Run Code Online (Sandbox Code Playgroud)

我可以从该基类继承,并让Angular选择注释吗?

pav*_*lgj 5

我相信建议您使用注释,因为它们更具可读性.

有些用例可能需要使用旧式映射,例如,将该类重用于多个组件/指令/控制器:

@NgComponent(selector: 'foo', map: const {'attr-a': '=>attrA'})
@NgComponent(selector: 'bar', map: const {'attr-a': '=>!attrA'})
class FooBarComponent {
   String attrA;
}
Run Code Online (Sandbox Code Playgroud)

如您所见,您可以定义不同的映射但使用相同的类.理论上这应该很少需要,但如果需要,它是可用的.

这两种表单目前都不支持继承.如果您对此有强烈的要求,提交功能请求.