我想定义一个新的映射注释。例如,如果属性看起来像控制器值,@ NgAttr会自动添加小胡子(大括号{{和}}),这不是很好吗?因此,无论我是否写
<pui-input pattern="{{ctrl.pattern}}" ng-model="ctrl.value">
或
<pui-input pattern="ctrl.pattern" ng-model="ctrl.value">
是否可以向AngularDart添加自定义映射?我的第一种方法是简单地从NgAttr派生,但它不起作用,因为注释不能包含Dart中的方法:
/**
* When applied as an annotation on a directive field specifies that
* the field is to be mapped to DOM attribute with the provided [attrName].
* The value of the attribute to be treated as a string, equivalent
* to `@` specification.
* If the value of the attribute looks like a property of a controller, it
* is surrounded by a mustache ({{ }}) if it is missing.
*/
class PuiAttr extends AttrFieldAnnotation {
final mappingSpec = '@';
const PuiAttr(String attrName) : super(attrName);
String get attrName => addMustache(super.attrName);
String addMustache(String attrName)
{
if (attrName.indexOf("{{") == 0) // Todo: find a nice regexp
if (attrName.indexOf("\.")>0)
return "{{$attrName}}";
return attrName;
}
}
请注意,胡子只是一个例子。我的问题是,是否可以将自定义映射添加到标准集@NgAttr,@ NonOneWay,@ NTTwoWay,@ NgOneWayOneTime和@NgCallback。
有任何想法或建议吗?