簡體   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