繁体   English   中英

单击表列(角度7)后,将焦点放在输入字段上

[英]Set focus on input field after click in table column (Angular 7)

我有一个问题,我需要将重点放在表中的单击列字段上。 我总是必须在该字段上单击两次以修改输入字段中的内容。

HTML:

<table mat-table [dataSource]="dataSource">
  <ng-container matColumnDef="ID">
    <th mat-header-cell *matHeaderCellDef> ID </th>
    <td mat-cell *matCellDef="let elem" (click)="editCell(elem.ID)" (keydown.enter)="editCell($event.keyCode)"> 
      <span *ngIf="!editable"> {{elem.ID}} </span>
      <mat-form-field *ngIf="editable">
        <input matInput [(ngModel)]="elem.ID">
      </mat-form-field>
    </td>
  </ng-container>
  ...
</table>

零件:

editCell(item: any): void {
    console.log('item: ', item);

    if(!this.editable) {
      this.editable = !this.editable;
    } else if(item === 13) {
      this.editable = !this.editable;
    }
}

我在其他线程中阅读了一些有关template reference variable和方法.focus()但它对我不起作用。

谁能帮我?

尝试这个

(focus)="editCell('focusin')" (focusout)="editCell('focus out')"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM