When implementing this directive verbatim how the demo describes, the lifecycle hook ngAfterViewChecked() {...} doesn't fire. After a quick search, it doesn't fire because directives don't have that hook because they don't have a view. As a result the code calling hljs.highlightBlock(snippet); never gets called.
Here is the relevant code:
ngAfterViewChecked() {
if (!this.done) {
const selector = this.highlightSelector || 'code';
if (this.elementRef.nativeElement.innerHTML && this.elementRef.nativeElement.querySelector) {
const snippets = this.elementRef.nativeElement.querySelectorAll(selector);
this.zone.runOutsideAngular(() => {
for (const snippet of snippets) {
hljs.highlightBlock(snippet);
}
});
this.done = true;
}
}
}
When implementing this directive verbatim how the demo describes, the lifecycle hook
ngAfterViewChecked() {...}
doesn't fire. After a quick search, it doesn't fire because directives don't have that hook because they don't have a view. As a result the code callinghljs.highlightBlock(snippet);
never gets called.Here is the relevant code:
Any thoughts/solutions?