在 Angular 10 项目中,我有一个表单,其中包含 2 个名为 Username 和 Password 的输入。我cdkFocusInitial在用户名字段上使用
属性,但它不关注页面加载。这是一个 StackBlitz 示例,显示了该问题https://stackblitz.com/edit/angular-4amzj4?file=src%2Fapp%2Ffocus-monitor-directives-example.html
<div class="example-focus-monitor">
<mat-form-field appearance="fill">
<mat-label>Username</mat-label>
<input cdkFocusInitial aria-label="Username" class="username"
matInput
placeholder="Enter Username" type="text">
</mat-form-field>
<br/>
<mat-form-field appearance="fill">
<mat-label>Password</mat-label>
<input aria-label=" Password" class="password" matInput placeholder="Enter Password"
type="text">
</mat-form-field>
</div>
[1]: https://stackblitz.com/edit/angular-4amzj4?file=src%2Fapp%2Ffocus-monitor-directives-example.html
Run Code Online (Sandbox Code Playgroud)