如何使属性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"
^^^^^^^^^^^^^^^^^^^^^^^
答案 0 :(得分:1)
在设置某个自定义属性时,请尝试attr.
语法
<input [attr.minlength]="minLength">