【问题标题】:Using Loess npm package with Angular4将 Loess npm 包与 Angular4 一起使用
【发布时间】:2017-12-16 14:46:35
【问题描述】:

我正在尝试导入 Loess 包,该包可通过 NPM 获得(它基本上是各种回归模型的实现以拟合数据)。我已经通过npm install loess --save 安装了它,它位于 node_modules 文件夹中。

不幸的是,我无法在我的组件中调用它的构造函数。我在组件中使用了以下导入语句:

import { Component, OnInit, Input, PLATFORM_ID, Inject } from '@angular/core';
import * as d3 from 'd3';
import * as loess from 'loess';
import { isPlatformBrowser } from '@angular/common';

但是,我不能在我的代码中调用构造函数,

没有

var model = new loess.Loess(data, options);

也没有

var model = new Loess(data, options);

我的开发者控制台总是抱怨

ERROR TypeError: loess.Loess is not a constructor
    at daily.component.ts?5fea:52

(或者在其他变体中只有new Loess([...])

如何在 Typescript/Angular 中调用类的构造函数?我知道 Loess 没有可用的类型,但这应该不是问题,不是吗?

【问题讨论】:

    标签: javascript angular typescript npm typescript-typings


    【解决方案1】:

    尝试使用黄土对象的默认属性。

    let model = new Loess.default(data, options);

    【讨论】:

    • 纯代码答案通常无助于指出问题发生的原因。请说明您的代码解决问题的原因。请阅读How do I write a good answer
    猜你喜欢
    • 2018-05-12
    • 2018-02-02
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 2018-04-28
    • 2021-05-13
    • 1970-01-01
    相关资源
    最近更新 更多