I have a use case where I need to render and transform an HTML node to HTML string and then add a ngx-bootstrap tooltip directive on a specific element in that that HTML string.
I can get the HTML to render fine, by either using InnerHTML with a pipe or creating a separate component, but always after the HTML is rendered the tooltip directive on the element is not registered and I'm not sure where to go from here. I would have though using pure: false
on the PIpe would solved it, but it does not.
Here is what've I tried with a pipe:
The Pipe With Tooltip Directive
import { documentToHtmlString } from '@contentful/rich-text-html-renderer';
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { BLOCKS, INLINES } from '@contentful/rich-text-types';
import { Store } from '@ngxs/store';
import { DeckState } from '../__states/deck';
@Pipe({ name: 'rich', pure: false })
export class RichContent implements PipeTransform {
constructor(private sanitizer: DomSanitizer, private store: Store) {
}
transform(content) {
let options = {
renderNode: {
[INLINES.EMBEDDED_ENTRY]: (node) => {
return `<b [tooltip]="node.data.target.fields.companyName">${node.data.target.fields.companyName}</b>`
}
}
}
var html = documentToHtmlString(content, options);
return this.sanitizer.bypassSecurityTrustHtml(html);
}
}
The HTML
<div [innerHTML]="content | rich"></div>
Outcome
Plain HTML without the tooltip directive working or being registered. For example:
<p>Here is an example from <b [tooltip]="node.data.target.fields.companyName">Mixpanel</b></p>
Hope someone can help me and point me in the right direction to solve this.