我正在使用角度为4的n2-handsontable进行项目 . 我似乎无法弄清楚当数据发生变化时如何刷新表格 . 我发现这篇文章:
这似乎是我想要的,但我无法弄清楚如何访问handsontable对象 . 我最初的想法是使用#进行绑定,但它没有按预期工作,只是将'undefined'传递给函数 .
component.html
<button class="btn btn-default" (click)="add(hot)">Add</button>
<hotTable [data]="_dataHot"
[colHeaders]="_columnHeadersHot"
[columns]="_columnsHot"
[options]="{contextMenu: true}"
#hot>
</hotTable>
component.ts
add(hot){
//do stuff
hot.render();
}
编辑:我可以通过做ngIf技巧强制渲染,但这似乎不是一个好的解决方案 .
2 回答
我最初遇到了同样的问题,但无法弄清楚如何访问渲染功能 . 在component.ts文件中使用以下行为我提供了一些技巧 .
我不确定的是为什么传递#hot为你返回undefined . 我在下面列出我的代码片段 .
component.html
component.ts
您需要使用
ViewChild
decorator在代码中获取对hot
的引用 . 您可以将其存储在同名变量中 .现在,您可以将类中的组件实例作为
this.hot
来访问 .