what I want to do exactly is to render text coming from the backend as a part of the angular template with full features like interpolations and directives (ngfor, if, switch).
Here is a brief example
template.component.ts
import { Component, OnInit } from '@angular/core';
import { MyService } from '../my.service';
@Component({
selector: 'app-template',
templateUrl: './template.component.html',
styleUrls: ['./template.component.scss']
})
export class TemplateComponent implements OnInit {
names: string[];
template: string;
constructor(
private myService: MyService
) { }
ngOnInit() {
this.myService.getTemplate('page-name').subscribe(data => {
// say data = <span *ngFor="let name of names">hello {{name}}</span>
this.template = data;
});
this.myService.getNames().subscribe(data => {
// say data = ['name 1', 'name 2', 'name 3']
this.names = data;
});
}
}
template.component.html
<div [innerHTML]="sample"></div>
Current output
hello {{name}}
Desired output
hello name 1
hello name 2
hello name 3
here is the closest thing i found to what i need https://blog.angularindepth.com/here-is-what-you-need-to-know-about-dynamic-components-in-angular-ac1e96167f9e