Angular Dart - 如何使属性minlength与动态值一起使用?

时间:2017-06-28 01:31:14

标签: forms validation angular-dart

如何使属性minlength与动态值一起使用?

例如,我有下一个代码:

<input class="form-control"
       id="name"
       type="text"
       [(ngModel)]="model.name"
       #name="ngForm"
       required
       [minLength]="minLength"/>
{{name.errors}}
当文本长度小于name.errors时,

minLength为空。

我也尝试过:

<input class="form-control"
       id="name"
       type="text"
       [(ngModel)]="model.name"
       #name="ngForm"
       required
       [minlength]="minLength"/>

和此:

<input class="form-control"
       id="name"
       type="text"
       [(ngModel)]="model.name"
       #name="ngForm"
       required
       minlength="{{minLength}}"/>

但我得到了下一个错误:

ParseErrorLevel.FATAL: Can't bind to 'minlength' since it isn't a known native property or known directive. Please fix typo or add to directives list.
[minlength]="minLength"
^^^^^^^^^^^^^^^^^^^^^^^

1 个答案:

答案 0 :(得分:1)

在设置某个自定义属性时,请尝试attr.语法

<input [attr.minlength]="minLength">