我会使用TypedJS库。
我使用npm install typed.js
安装了它
然后在.angular-cli.json
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/typed.js/lib/typed.js"
],
在我的组件中:
import { Component, OnInit } from '@angular/core';
import * as Typed from 'typed.js';
@Component({
selector: 'app-a-propos',
templateUrl: './a-propos.component.html',
styleUrls: ['./a-propos.component.css']
})
export class AProposComponent implements OnInit {
constructor() { }
ngOnInit() {
var typed2 = new Typed('#typed', {
strings: ["<b>#Font End ?</b>", "<b>#Front End ?</b>", "<b>#Back End ?</b>", "<b> #Fullstack ?</b>", "<b>ça m'interesse !</b>"],
typeSpeed: 30,
backDelay: 2000,
loop: true,
});
}
}
和HTML
<p id="typed"> </p>
我收到此错误:
ERROR TypeError: Cannot read property 'tagName' of null