首页 > 解决方案 > 如何将 JavaScript 库中触发的 onclick 事件绑定到 Angular 函数?

问题描述

如何将 Angular 组件内的外部可视库 (DHTMLX Gantt) 触发的“onclick”事件与同一个 Angular 组件的功能绑定?

环境:

组件.html

<div #gantt_here style='width: 100%; height: 100%;'></div>

组件.ts

export class ProjectManagementGanttComponent implements OnInit {
  @ViewChild('gantt_here') ganttContainer: ElementRef;

  constructor() {
  }

  ngOnInit() {

    // Config Gantt Library
    gantt.config.columns = [
      {name: 'tree', width: 30,
        template: '<input type=button onclick=expand_task(' + task.id + ') value=+>'
      },
      {name: 'text',       label: 'Task name',  width: '*'}
    ];

    // Init Gantt Library
    gantt.init(this.ganttContainer.nativeElement);
  }

标签: javascriptangulardhtmlx

解决方案


推荐阅读