将angulard.js集成在角度4中

时间:2017-11-06 05:53:01

标签: angular

在角度4中集成typed.js时出现以下错误。 错误TypeError: WEBPACK_IMPORTED_MODULE_2_typed_js .Typed不是构造函数

我的组件是:

 import { Component, OnInit } from '@angular/core';
import { Typed } from 'typed.js';
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {


  ngOnInit() {
    let options = {
          strings: ["Books.", "Cinema.", "Paintings.","Music."],
          typeSpeed: 100,
          backSpeed: 100,
          showCursor: true,
          cursorChar: "|",
          loop:true
        }

      let typed = new Typed(".typing-element", options);
  }

}

我的Html是

<div class="container">
        <div class="home-header-title">
            <span class="title">what you like </span>
            <span class="typing-element"></span>
        </div>
    </div>

2 个答案:

答案 0 :(得分:5)

你应该改变

import { Typed } from 'typed.js';

import * as Typed from 'typed.js';

答案 1 :(得分:0)

如果您要导入js文件,请使用declare关键字

declare var Typed: any;

import 'path_to_your_js/typed.js';

export class HomeComponent implements OnInit {


  ngOnInit() {
    let options = {
          strings: ["Books.", "Cinema.", "Paintings.","Music."],
          typeSpeed: 100,
          backSpeed: 100,
          showCursor: true,
          cursorChar: "|",
          loop:true
        }

      let typed = new Typed(".typing-element", options);
  }

}