Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one component have multiple templates?

Is there a way for Angular 2 component to use many template files base on where i want to place it?

For example, I have a login component and i want to place it two times on my website with two different designs.

Is there a way that i can pass template to a component?


1 Answers

Not sure if NG2 has built-in way to support this. I just used a base component class to contain all or most logic and data, without a html template. Then in derived component classes, just need to declare constructor calling super(...), and define respective html template.

If your application is complex, likely you will be using module to instantiate classes, then make sure you declare moduleId: module.id in the Component attribute, otherwise the NG2 runtime may complain the html template could not be loaded.

like image 96
ZZZ Avatar answered Aug 21 '26 01:08

ZZZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!