首页 > 解决方案 > $(...)甘特图不是函数

问题描述

嘿,我正面临一个问题,我想在我的 Angular 项目中显示甘特图,所以我正在使用 .chart jquery.gantt 插件。

我在 angular.json 中添加了脚本,如下所示:

"scripts": [ 
          "node_modules/jquery/dist/jquery.min.js" , 
          "node_modules/popper.js/dist/umd/popper.min.js" , 
          "node_modules/bootstrap/dist/js/bootstrap.min.js" , 
          "src/assets/js/jquery.fn.gantt.min.js"

添加此代码以显示图表后:

ngOnInit(): void {   

  ($(".chart_div") as any).gantt({
  source: this.myData , 
  scale: "weeks",
  minScale: "weeks",
  maxScale: "months",
  onItemClick: function(data:any) {
      alert("Item clicked - show some details");
  },
  onAddClick: function(dt:any, rowId:any) {
      alert("Empty space clicked - add an item!");
  },
  onRender: function() {
      console.log("chart rendered");
  }
});  
} 

但我在控制台收到此错误:错误类型错误:jquery__WEBPACK_IMPORTED_MODULE_0__(...).gantt is not a function

请问有什么解决办法吗?

标签: javascriptangulartypescript

解决方案


推荐阅读