Angular Set Input Cursor to next input, PS : next input tag will be dynamic add on keyEnter of previous input click

린다 샘

입력 태그와 함께 for 루프를 사용하고 있습니다. 사용자가 무언가를 입력하고 Enter 키를 누르면 명령이 제출되고 현재 for 루프가 다른 입력 태그로 푸시됩니다. 커서를 다음 입력으로 이동하고 싶습니다. srcElement를 가져와 다음 요소로 포커스를 이동하는 많은 솔루션이 있지만 여기에는 다음 요소가 동적으로 추가됩니다.

shell.component.html

<div class="shell">
    <table>
        <tr *ngFor="let text of shellText">
            <ng-container *ngIf="getType(text['type']);else input">
                <td style="width: 2%">{{text['preText']}}</td>
                <td>{{text['text']}}</td>
            </ng-container>
            <ng-template #input>
                <td style="width: 2%">{{text['preText']}}</td>
                <td><input [readonly]="text['type'] == 'command'" class="shell-input"
                        (keyup.enter)="onEnter($event,text['line'])" [(ngModel)]="text['text']" mat-input type="text" /></td>
            </ng-template>
        </tr>
    </table>
</div>

shell.component.ts

  onEnter(event, line) {
    if (this.shellText[line - 1].text.trim().endsWith(':')) {
      this.shellText.push({ 'type': CLASSES['CONTINUE_COMMAND'], 'line': line + 1, 'preText': '', 'text': '    ' },)
    } else {
      this.shellText.push({ 'type': CLASSES['CURRENT_COMMAND'], 'line': line + 1, 'preText': '>>>', 'text': '' },)
    }
    this.shellText[line - 1]['type'] = CLASSES['COMMAND']

    setTimeout(() => {
      this.setFocus(event)
    }, 2000);
  }


  setFocus(event) {
    debugger
    let element = event.srcElement.nextElementSibling; // get the sibling element
    console.log(element)
    if (element == null)  // check if its null
      return;
    else
      element.focus();   // focus if not null
  }

참고 : 파이썬 셸을 만들려고합니다.

Aliasgher Nooruddin

shell.component.ts

  setFocusevent) {
    let element = event.srcElement.parentElement.parentElement.nextElementSibling.lastElementChild.firstElementChild; // get the sibling element
    if (element == null)  // check if its null
      return;
    else
      element.focus();   // focus if not null
  }
  1. 먼저 <input>태그 의 참조를 얻습니다.
  2. 그런 다음 부모 요소를 얻습니다. <td>
  3. 그런 다음 더 나아가 <tr>
  4. 그런 다음 <tr>동적으로 생성 될 다음을 참조합니다.
  5. 그런 다음 마지막 요소가 될 마지막 요소에 액세스합니다. <td>
  6. 그런 다음 원하는 <input>요소 를 가리키고 초점을 추가합니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Angular Set Input Cursor to next input, PS : next input tag will be dynamic add on keyEnter of previous input click

분류에서Dev

jquery - change input value when go to next

분류에서Dev

Add value of input field to anchor/link tag

분류에서Dev

Ionic / Angular ng-click for select input

분류에서Dev

Insert string to <input> tag

분류에서Dev

Meteor dynamic input fields

분류에서Dev

why getchar() doesn't get next value from input?

분류에서Dev

Meteor Shell overwriting previous input

분류에서Dev

Set input as invalid

분류에서Dev

Input tag file value jquery

분류에서Dev

Read input into a dynamic sized int?

분류에서Dev

how can i add dynamic labels and text input field in xcode

분류에서Dev

Get Cursor Position With Input type number

분류에서Dev

show cursor/caret at the beginning of input box

분류에서Dev

Jquery add input field and datepicker

분류에서Dev

Angular radio buttons and custom input

분류에서Dev

Angular Xeditable input type url

분류에서Dev

Clojure: Executing an operation n times using the output as input of next operation (a-la reduce)

분류에서Dev

Zsh / git: Tab autocomplete not working if "HEAD^" is next to last word on input row

분류에서Dev

input tag inside ng-repeat angularjs

분류에서Dev

jQuery push multiple values in input tag

분류에서Dev

dynamic calculation of input fields using php javascript

분류에서Dev

Dynamic object creation from user input

분류에서Dev

Generate dynamic input fields based on selection

분류에서Dev

Why is a dynamic input value not showing a change with Angularjs?

분류에서Dev

Save user input string to variable on button click

분류에서Dev

while (input.hasNext ()) 내부의 여러 input.next ()는 Java에서 NoSuchElementException을 트리거합니다.

분류에서Dev

while (input.hasNext ()) 내부의 여러 input.next ()는 Java에서 NoSuchElementException을 트리거합니다.

분류에서Dev

PS / 2 키보드의 / dev / input / 읽기

Related 관련 기사

  1. 1

    Angular Set Input Cursor to next input, PS : next input tag will be dynamic add on keyEnter of previous input click

  2. 2

    jquery - change input value when go to next

  3. 3

    Add value of input field to anchor/link tag

  4. 4

    Ionic / Angular ng-click for select input

  5. 5

    Insert string to <input> tag

  6. 6

    Meteor dynamic input fields

  7. 7

    why getchar() doesn't get next value from input?

  8. 8

    Meteor Shell overwriting previous input

  9. 9

    Set input as invalid

  10. 10

    Input tag file value jquery

  11. 11

    Read input into a dynamic sized int?

  12. 12

    how can i add dynamic labels and text input field in xcode

  13. 13

    Get Cursor Position With Input type number

  14. 14

    show cursor/caret at the beginning of input box

  15. 15

    Jquery add input field and datepicker

  16. 16

    Angular radio buttons and custom input

  17. 17

    Angular Xeditable input type url

  18. 18

    Clojure: Executing an operation n times using the output as input of next operation (a-la reduce)

  19. 19

    Zsh / git: Tab autocomplete not working if "HEAD^" is next to last word on input row

  20. 20

    input tag inside ng-repeat angularjs

  21. 21

    jQuery push multiple values in input tag

  22. 22

    dynamic calculation of input fields using php javascript

  23. 23

    Dynamic object creation from user input

  24. 24

    Generate dynamic input fields based on selection

  25. 25

    Why is a dynamic input value not showing a change with Angularjs?

  26. 26

    Save user input string to variable on button click

  27. 27

    while (input.hasNext ()) 내부의 여러 input.next ()는 Java에서 NoSuchElementException을 트리거합니다.

  28. 28

    while (input.hasNext ()) 내부의 여러 input.next ()는 Java에서 NoSuchElementException을 트리거합니다.

  29. 29

    PS / 2 키보드의 / dev / input / 읽기

뜨겁다태그

보관