我需要使用 Validators.pattern 在响应式表单(表单控件)中提出验证模式。条件是字母数字,只允许使用下划线_、连字符-。不应允许任何类型的空间。是否有任何一种模式可以帮助我实现这一目标。
谢谢。
与Google登录页面类似,单击事件后,我希望自动聚焦于输入元素。我尝试了@ViewChild('id')和document.getElementId('id')。两者都不起作用。它始终为null或未定义。我该如何实现?
<mat-form-field class="example-full-width col-sm-4">
<input autofocus id="login-username" matInput
formControlName="userName" minlength="5" maxlength="20"
name="userName" placeholder="Username" required #input>
</mat-form-field>
<div class="col-sm-12">
<button (click)="changeView()" type="button" mat-raised-
button color="primary">Next</button>
</div>
<mat-form-field class="example-full-width col-sm-4"
#passwordInput>
<input autofocus type="password" matInput
placeholder="Password" minlength="5" maxlength="20"
formControlName="userPassword" #passwordInput>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)