首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误TypeError:使用Typedjs时无法读取空属性'tagName‘

错误TypeError:使用Typedjs时无法读取空属性'tagName‘
EN

Stack Overflow用户
提问于 2018-03-11 20:57:25
回答 1查看 3.2K关注 0票数 3

我会使用TypedJS库。

我使用npm install typed.js安装了它,然后在.ange-cli.json中包含了typed.js文件

代码语言:javascript
复制
"scripts": [
  "../node_modules/jquery/dist/jquery.min.js",
  "../node_modules/typed.js/lib/typed.js"
],

在我的部分:

代码语言:javascript
复制
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

代码语言:javascript
复制
<p id="typed"> </p>

我知道这个错误:

代码语言:javascript
复制
ERROR TypeError: Cannot read property 'tagName' of null
EN

回答 1

Stack Overflow用户

发布于 2022-03-22 14:18:55

您需要在视图初始化后设置类型化对象。

代码语言:javascript
复制
export class AProposComponent implements AfterViewInit{

  constructor() { }

  ngAfterViewInit() {
    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,

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

https://stackoverflow.com/questions/49225019

复制
相关文章

相似问题

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