【发布时间】:2019-01-28 17:23:09
【问题描述】:
我正在使用 Ionic 3/Angular 5 试图为组件中的一个非常高的表格设置一个浮动水平滚动条。我遇到了这个应该很好用的解决方案:Floating horizontal scroll bar for html table
http://jsfiddle.net/cowboy/45rEs/show/
问题是我无法将 jQuery 函数导入到我的组件中。
到目前为止,我已经成功安装了 jQuery,并且它工作正常。此外,我已将 jQuery 插件导入我的索引:
<script src="assets/jquery.ba-floatingscrollbar.min.js"></script>
如何将它包含在我的组件中?目前我收到一个错误:
类型“JQuery”上不存在属性“floatingScrollbar”
组件
import { Component } from '@angular/core';
import * as $ from 'jquery';
@Component({
selector: 'tall-table',
templateUrl: 'tall-table.html'
})
export class TallTableComponent {
constructor() {
}
ngAfterViewInit(): void {
$('#horz-scroll-wrapper').floatingScrollbar();
}
}
tall-table.html
<div id="horz-scroll-wrapper" style="width: 300px; overflow: scroll">
<div style="height: 100%;">
<table class='sample'>
<tbody>
<tr *ngFor="let row of [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]">
<td >abcdefghijklmnopqrstuvwxyz</td><td >ABCDEFGHIJKLMNOPQRSTUVWXYZ</td><td >1234567890</td><td >0987654321</td><td >abcdefghijklmnopqrstuvwxyz</td><td >ABCDEFGHIJKLMNOPQRSTUVWXYZ</td><td >1234567890</td><td >0987654321</td>
</tr>
</tbody>
</table>
</div>
</div>
【问题讨论】:
-
你在 chrome 的控制台中试过了吗?我会先尝试一下,看看是您的导入问题还是其他问题...