Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 表单控件不是';我的一个输入字段不工作_Html_Angular - Fatal编程技术网

Html 表单控件不是';我的一个输入字段不工作

Html 表单控件不是';我的一个输入字段不工作,html,angular,Html,Angular,我有一个注册表,有多个输入字段(用户名、电子邮件、密码、确认密码)。我在诸如min length之类的字段上设置了一些表单控件,但出于某种原因,它适用于除用户名以外的所有字段 以下是用户名字段: <div class="form-control-group"> <label class="label" for="input-name">Username:</label> <input nbInput [(ngModel)]="user.us

我有一个注册表,有多个输入字段(用户名、电子邮件、密码、确认密码)。我在诸如min length之类的字段上设置了一些表单控件,但出于某种原因,它适用于除用户名以外的所有字段

以下是用户名字段:

<div class="form-control-group">
<label class="label" for="input-name">Username:</label>
<input nbInput
       [(ngModel)]="user.username"
       #username="ngModel"
       id="input-name"
       name="username"
       placeholder="Full name"
       autofocus
       fullWidth
       [status]="email.dirty ? (email.invalid  ? 'danger' : 'success') : ''"
       [required]="getConfigValue('forms.validation.username.required')"
       [minlength]="getConfigValue('forms.validation.username.minLength')"
       [maxlength]="getConfigValue('forms.validation.username.maxLength')"
       [attr.aria-invalid]="username.invalid && username.touched ? true : null">
<ng-container *ngIf="username.invalid && username.touched">
  <p class="error-message" *ngIf="username.errors?.required">
    Username is required!
  </p>
  <p class="error-message" *ngIf="username.errors?.minlength || username.errors?.maxlength">
    Username should contains
    from {{getConfigValue('forms.validation.username.minLength')}}
    to {{getConfigValue('forms.validation.username.maxLength')}}
    characters
  </p>
</ng-container>

用户名:

用户名是必需的!

用户名应包含 来自{{getConfigValue('forms.validation.username.minLength')} 到{{getConfigValue('forms.validation.username.maxLength')} 人物


blapaz在评论中回答了这个问题,但看起来您只需要更改模型绑定。目前,您有:

[(ngModel)]="user.username"
将其更改为:

[(ngModel)]="username"

应该解决您的问题

检查此参考答案什么不起作用?请详细说明。如果我单击用户名,然后切换到另一个输入字段,则不会显示用户名是必需的,或者如果我输入的用户名小于2或大于10,则不会显示minlength/maxlength错误。您可以显示您的用户模型吗?您是否可能缺少username属性?另外,您确定没有将其他表单控件与模板控件一起使用吗?(这导致了一些奇怪的问题)。这些是在黑暗中拍摄的tbh,据我所知,此模板看起来很好。看起来您的模型绑定到了
user.username
,您的验证消息中只有
username
。因此,该值被绑定到
user.username
,但您只需检查
username