如何使用angular2专注于新添加的行

时间:2018-08-21 07:03:15

标签: bootstrap-4 angular2-directives

我有一个要求,我想集中精力使用angular2将新添加的行集中到html表中。下面是代码。

<div style="height:200px;overflow-y:auto">
    <table class="table table-bordered table-hover">
        <thead>
        <tr class="d-flex">
            <th class="col-3">Q.No</th>
            <th class="col-4">Record Answer</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let answer of answerPaper; let i = index" class="d-flex">
            <td class="col-3">answer.no</td>
            <td class="col-4">answer.name</td>
        </tr>
        </tbody>
    </table>
</div>
<button (click)="addrow()">Add Row</button>

下面是组件ts,我在其中编写了代码以添加新行。您可以在这里提出有关如何关注新添加行的建议。

public addRow(){
    this.answerPaper.push({});
} 

以上方法在表中添加了一行,但是即使有滚动条,我又如何聚焦于添加的新行?

0 个答案:

没有答案
相关问题