我是Angular的新手.
我正在尝试使用xterm.js(https://xtermjs.org/),但显示效果很差.
这是渲染:
Render
我创建了一个xterm组件. xterm.component.ts文件代码为:
import { Component, OnInit } from '@angular/core';
import { Terminal } from "xterm";
@Component({
selector: 'app-xterm',
templateUrl: './xterm.component.html',
styleUrls: ['./xterm.component.css'],
})
export class XtermComponent implements OnInit {
public term: Terminal;
container: HTMLElement;
constructor() { }
ngOnInit() {
this.term = new Terminal();
this.container = document.getElementById('terminal');
this.term.open(this.container);
this.term.writeln('Welcome to xterm.js');
}
}
我的xterm.component.html仅包含以下内容:
<div id="terminal"></div>
我真的不知道该怎么做…
在此先感谢大家
解决方法:
尝试通过使用哈希符号在模板引用变量中使用
<div #myTerminal></div>
并在组件中
@ViewChild('myTerminal') terminalDiv: ElementRef;
在ngOnInit中
ngOnInit() {
this.term = new Terminal();
this.term.open(this.terminalDiv.nativeElement);
this.term.writeln('Welcome to xterm.js');
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。