Skip to content

How to use in Angular 16? #25

@bakotiinii

Description

@bakotiinii

I followed the instruction but and got "Can't find hljs under window" warning in console. So what i did:

  1. Add in my app.module.ts
import {HIGHLIGHTJS_CONFIG, HighlightJsConfig, HighlightJsModule} from 'ngx-highlight-js';

@NgModule({
  declarations: [
    AppComponent,
    QuestionPageComponent,
    QuestionComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    ReactiveFormsModule,
    HighlightJsModule,
  ],
  providers: [
    {
      provide: HIGHLIGHTJS_CONFIG,
      useValue: {
        lang: 'html'
      } as HighlightJsConfig
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
  1. Download css/js and create local highlight.css/highlight.js

im my component:

@Component({
  selector: 'app-question',
  templateUrl: './question.component.html',
  styleUrls: [
    './question.component.css',
    './question.component-bar.css',
    './question.component-media.css',
    './highlight.component.css'
  ]
})

in angular.json

"scripts": [
  "src/assets/highlight.js"
]

p.s. also i tried adding urls to cnd in html file.

And in component.html

<textarea highlight-js [lang]="'typescript'">
/* tslint:disable */
import { Component } from '@angular/core';

@Component({
  selector: 'demo',
  templateUrl: './demo.component.html',
  styleUrls: ['./demo.component.scss']
})
export class DemoComponent {
  switchStatus: boolean = true;
}
</textarea>

And no render and warning about hljs in console. Do you have any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions