【发布时间】:2017-01-23 17:06:54
【问题描述】:
我有这张表,它是TableComponent 的一部分:
<table class="th-tracker-table th-environmental-table" #trackerTable>
当swapProjectsGroups() 方法被触发时,我想从MyComponent 访问它并滚动到组件顶部
export class MyComponent {
@ViewChild("#trackerTable") trackerTable: ElementRef;
public swapProjectsGroups() {
this.trackerTable.nativeElement.scrollTo(0,0); //Error: Cannot read property 'scrollTo' of undefined
}
}
但我得到了Cannot read property 'scrollTo' of undefined,我是否缺少初始化 nativeElement 的内容?
angular2 的实现方式是什么?
【问题讨论】:
-
你知道怎么做吗?
标签: angular typescript angular2-template angular2-directives