I have a string coming from the server formatted like this:
"Lorem ipsum, <b>#LOGO#
dolor</b> sit amet #LOGO#
consectetur adipisicing elit #LOGO#
."
I have to swap the #LOGO#
substrings with an .svg in my assets folder.
I can't insert the component dynamically, since it's plain text. I also can't just convert the svg to a string constant, because it's used elsewhere as an <img>
source. I can't import the .svg file since it's not a module:
import * as Icon from '@src/assets/icon.svg'
Cannot find module 'src/assets/icon.svg' or its corresponding type declarations.
I tried to add a 'gloabl.d.ts' or 'custom.d.ts' file to the project. VSCode stopped showing the error, but Angular didn't compile, showing the same error. Tried require
'ing the file, but it's Angular, it doesn't allow that
The only approach that did work is to create a pipe that repalces the #LOGO# and pass the end result to the innerHtml
attribute. But it just feels.. wrong
export class FormatPremRubPipe implements PipeTransform {
transform(source: string): string {
return source.replace(
'#LOGO#',
`<img src="/assets/logo.svg" />`
);
}
}
So what are my options?