I strongly suggest not mixing templates and component code. Even if you get it to work in development mode, it will break in mysterious ways with the ahead-of-time compiler. Keep template code in templates.
There is always another way. You could parse these “sequences of characters” into a heterogeneous array of objects, loop across this array with an ngFor and render links when the object is a link type.
I guess other peoples’ experiences may vary, but every single time I have started out doing anything with HTML inside an Angular 2 component, I eventually gave up and did literally anything to avoid doing so. The framework really really does not want you to be doing this.
I just had to take a moment from banging my head against various solid objects to second this statement. It is so obtusely difficult to work with anything beyond basic html content outside of a template in angular2. Very frustrating if you’re trying to keep your data uncoupled from the view components.