首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Angular typescript中使用Timetable.js?

如何在Angular typescript中使用Timetable.js?
EN

Stack Overflow用户
提问于 2018-07-26 04:20:56
回答 1查看 1.3K关注 0票数 1

我正在尝试将这个很好的javascript插件实现到一个Angular6项目中:Timetable.js / on Github

为了寻找这样做的方法,我遇到了这个:How to use Timetable.js in ionic2 typescript。这篇文章已经发布两年了,这个问题似乎还没有解决。基于tmnrkb发布的代码,我在angular.json文件中声明了js脚本文件后,在我的app.component中编写了该代码:

代码语言:javascript
复制
import { Component } from '@angular/core';

declare class Timetable {
  constructor();
  scope: string;
  locations: Array<string>;
  events: Array<any>;
  Renderer(tt: any): any;
  setScope(start: number, end: number);
  addLocations(locations: Array<string>);
  addEvent(artistCode: string, stageCode: string, startDate: Date, endDate: Date);
}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  timetable = new Timetable();

  constructor() {
    this.addTimeTable();
  }

  addTimeTable() {
    this.timetable.setScope(9, 3);

    this.timetable.addLocations(['London', 'Paris', 'Los Angeles']);

    this.timetable.addEvent('Sightseeing', 'London', new Date(2018, 8, 25, 9), new Date(2018, 8, 26, 12));

    this.timetable.addEvent('Zumba', 'Paris', new Date(2018, 8, 27, 9), new Date(2018, 8, 29, 12));

    this.timetable.addEvent('Cocktails', 'Los Angeles', new Date(2018, 8, 22, 9), new Date(2018, 8, 23, 12));

    const renderer = this.timetable.Renderer(this.timetable);
    // const renderer = new Timetable.Renderer(this.timetable);
    renderer.draw('.timetable');
  }



}

当我运行ng serve时,它会编译代码,但在控制台中,我得到了这个错误:

代码语言:javascript
复制
AppComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: this.timetable.Renderer is not a function
    at AppComponent.push../src/app/app.component.ts.AppComponent.addTimeTable (app.component.ts:39)
    at new AppComponent (app.component.ts:25)

所以我想知道为什么它说渲染器不是一个函数。

EN

回答 1

Stack Overflow用户

发布于 2018-07-27 08:42:04

因此,基于Timetable.js (the plugin's Github),我设法通过将其转换为Typescript来使其在Angular中工作。这是我Github上的结果,如果有人感兴趣的话。感谢stevenaanen因为他的插件正是我需要的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51527072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档