Clé*_*uin 7 javascript angular xtermjs
我是 Angular 的新手。我正在尝试使用 xterm.js ( https://xtermjs.org/ ),但显示效果不佳。这是渲染: 渲染
我创建了一个 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');
}
}
Run Code Online (Sandbox Code Playgroud)
我的 xterm.component.html 只包含这个:
<div id="terminal"></div>
Run Code Online (Sandbox Code Playgroud)
我真的不知道该怎么做更多......提前致谢伙计们
必须设置组件封装
@Component({
encapsulation: ViewEncapsulation.None,
...
})
Run Code Online (Sandbox Code Playgroud)
小智 3
尝试通过使用哈希符号在模板引用变量中使用
<div #myTerminal></div>
Run Code Online (Sandbox Code Playgroud)
并在组件中
@ViewChild('myTerminal') terminalDiv: ElementRef;
Run Code Online (Sandbox Code Playgroud)
在ngOnInit
ngOnInit() {
this.term = new Terminal();
this.term.open(this.terminalDiv.nativeElement);
this.term.writeln('Welcome to xterm.js');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3215 次 |
| 最近记录: |