I'm using ngx-markdown to render my FAQ, in it, I've links to external resource (starting http
) and internal stuff (starting with /
).
I'd like to pass the angular router to my markedOptionsFactory in order to use it for local resources.
Is there a way to pass angular router in the decorator when importing the module:
imports: [
[...]
MarkdownModule.forRoot({
provide: MarkedOptions,
useFactory: markedOptionsFactory,
}),
[...]
],
FYI, my markedOptionsFactory
looks like:
export function markedOptionsFactory(): MarkedOptions {
const renderer = new MarkedRenderer();
renderer.link = (href: string, title: string, text: string) => {
const isLocalLink = /^\//.test(href);
const target = isLocalLink ? '_self' : '_blank';
const hrefContent = isLocalLink ? `javascript:router.navigateByUrl('${href}')` : href;
return `<a href="${hrefContent}" target="${target}">${text}</a>`;
};
return {
renderer: renderer,
[...]
};
}