我想在ngIf被解雇时然后textarea获得焦点。我不想用@ViewChildren(它加载项目)来做这件事。
现在我有(click)='myInput.focus()'
,这只设置焦点点击..我也尝试用autofocus
但它只被触发一次,当第二次触发ngIf然后自动对焦没有&# 39;工作。
div *ngIf="i == editable && editCommentUp" (click)='myInput.focus()'>
<div class="formCommentComment">
<div class="formPanel">
</div>
<textarea #myInput id="formCommentComment" [(ngModel)]="comment.comment"></textarea>
</div>
<div class="wrapperFormButton">
<button id="formCommentButton" (click)="editComment('/edit-comment', comment._id, comment.comment, i)"> Send </button>
<button id="formCommentButtonCancel" (click)="cancel()"> Send</button>
<i class="{{enterGood}} enterGood"> </i>
<div class="errorMessage" style="margin: 10px 0 0;">{{errorMessage}}</div>
</div>
</div>