简体   繁体   English

在Angular CLI中添加JavaScript库/代码

[英]Add JavaScript library/code in Angular CLI

I am trying to use the Typed.js library in Angular CLI, but I couldn't manage to make it work. 我试图在Angular CLI中使用Typed.js库,但是我无法使其正常运行。 I followed the instructions in How can I use JavaScript code in Angular 7? 我遵循了如何在Angular 7中使用JavaScript代码中的说明 : copied the jQuery library and typed scrips in assets folder, added a path to the files in angular.json, but I am not sure what to do in the component.ts file: :复制jQuery库并在Assets文件夹中键入scrips,在angular.json中为文件添加路径,但是我不确定在component.ts文件中该怎么做:

This is my component.ts code: 这是我的component.ts代码:

import { Component, OnInit } from '@angular/core';
declare var jQuery: any;
declare var Typed: any;

@Component({
  selector: 'app-typing',
  templateUrl: './typing.component.html',
  styleUrls: ['./typing.component.scss']
})
export class TypingComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    var typed = new Typed('.typed', {
      strings: ["First sentence.", "Second sentence."],
      typeSpeed: 30
    });
  }

  onComplete() {
  }

}

I am pretty sure what I wrote in ngOnInit() is wrong, but how can I make it right? 我很确定自己在ngOnInit()中写的东西是错误的,但是我该怎么做呢?

You have to import typed.js in order to be able to use it. 您必须导入typed.js才能使用它。 Declaring it as variable with type of any does not make any sense. 将其声明为类型为any变量没有任何意义。 Try importing it instead like this: import Typed from 'typed.js'; 尝试像这样导入它: import Typed from 'typed.js';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM