2

I have a simple component as follows:-

 @Component({
    selector: 'list',
    templateUrl: './list.component.html',
    styleUrls: ['./list.component.css']
});
export class listComponent implments onInit {
   @Input customTemplateUrl: string;
}

Can I load the custom template passed as @Input as the template for the component?

Abhidev
  • 7,063
  • 6
  • 21
  • 26
  • http://stackoverflow.com/questions/34784778/equivalent-of-compile-in-angular-2/37044960#37044960 – Günter Zöchbauer Mar 22 '17 at 10:40
  • I did come through this while searching, so there is no simpler way for it? – Abhidev Mar 22 '17 at 10:51
  • No. Angular by default compiles templates when you create a deployable (AoT) and then doesn't deal with Angular-specific syntax in HTML at runtime at all. You can include the dynamic platform to be able to compile components at runtime to get this functionality back. The linked answer shows how you can do this. There are packages available that make it easier, but I don't remember the name because I don't use it myself. These packages just wrap what the linked answer shows into a component or something like that. – Günter Zöchbauer Mar 22 '17 at 10:54
  • I don't know what you want to achieve but maybe you can create components for each template and use `` on the parent component instead of assigning a template? – Bünyamin Sarıgül Mar 22 '17 at 12:44

0 Answers0