【发布时间】:2020-01-01 19:36:23
【问题描述】:
有一个带有 *ngFor 显示项目的组件。我的目标是向下滚动到带有锚 #3 的元素。
代码:
@Component({
selector: 'my-app',
template: `
<button (click)="scroll(3)">scroll 2</button>
<li *ngFor="let item of itemList; let i = index" [attr.data-index]="i">{{i}} {{item}}</li>
`,
})
class HomeComponent {
text = 'foo';
testObject = {fieldFirst:'foo'};
itemList = [
//...
];
scroll(el: HTMLElement) {
el.scrollIntoView();
}
}
有一个 jsfiddle example。
我不知道如何为其设置取消点?
【问题讨论】:
-
你试过我建议的答案了吗?
标签: javascript html angular scroll ngfor