node.js - 用 Angular 突出显示?

标签 node.js angular typescript highlightjs

ng2-smart-table application documentation具有如下所示的 code 元素片段:

<code highlight class="typescript">{{ snippets.require }}</code>

resulting documentation looks like this .

当查看生成的应用程序 html 时,它看起来像 highlightjs正在进行突出显示,但我没有看到将执行转换的 Angular 依赖项的导入(或脚本的任何预处理),所以只是想知道它是如何工作的?

根据答案

用 Angular 做这件事是多么简单,真是太酷了:

import { Directive, ElementRef, AfterViewInit } from '@angular/core';
import * as hljs from 'highlight.js';

@Directive({
selector: 'code[highlight]',
})
export class HighlightCodeDirective implements AfterViewInit {

constructor(private elRef: ElementRef) { }

ngAfterViewInit() {
    hljs.highlightBlock(this.elRef.nativeElement);
}

}

最佳答案

仔细检查代码有一个 highlight directive (ng2-smart-table/src/app/shared/directives/highlight.directive.ts) 使用 highlightjs。它是示例应用程序的一部分,而不是库的一部分,因此如果您想在您的应用程序中执行相同的操作,则需要复制它。

关于node.js - 用 Angular 突出显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53421239/

相关文章:

javascript - Nodemon - 安装期间为 "clean exit - waiting for changes before restart"

node.js - 从已经定义的模型中获取 Sequelize.js ENUM 值

node.js - Mongoose 不允许我为 Number 插入空值?

angular - 在 Angular 7 中将数据恢复为 react 形式

angular - ngFor 在 ionic 2 中抛出 "error trying to diff"

typescript - 在 typescript 中选择一种交叉类型

angularjs - 到 child 的 Angular 路由 - 来自不同 parent 的 child

javascript - Angular 是平台还是框架?

json - 如何在 React 中使用 JSON 对象

angular - "Error: Uncaught (in promise): TypeError: Cannot read property ' 长度 ' of undefined"