模态Angular 4中的自动对焦不起作用

Ale*_*dro 1 angular-material2 angular

我必须将输入集中在加载模式上,但是如果我使用html5属性,autofocus它似乎无法正常工作。有可能使其工作吗?

<div class="col-md-6">
 <div class="form-group label-floating">
  <label class="control-label">
    {{'ticketbundle.busroutedetail.dialog.labels.buslinename'
     | translate }}<span class="star">*</span>
   </label><input autofocus class="form-control" id="name" required
   [(ngModel)]="busRouteDetail.name" name="name" #busRouteDetailname>
 </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我正在使用角材2

Wil*_*ell 5

如果使用的是“材质”对话框,则可以用于cdkFocusInitial指定初始焦点所在的位置。

<input cdkFocusInitial type="text">
Run Code Online (Sandbox Code Playgroud)

请参阅此示例

  • 我不得不仔细检查源代码,但是cdkFocusInitial属性实际上并没有管理任何逻辑。使用`cdkTrapFocus`时,它只是一个地方标记 (3认同)