0

I'm looking for a way to use my components replacing the standard templates with custom ones, but still keeping AOT compatibility.

I know it can be done writing a new component which replaces the original template, but I'd like to provide some convention-over-configuration instead.

Goal: if you use my-component and want to replace its original template, you just have to create a template named overrides/my-component.html in the folder hosting the parent component.

Take for instance the ad-banner component used in the Dynamic Component Loader official Angular example: in that example hero-job-ad and hero-profile components are simply meant at replacing the original template within a certain context. I consider that code as quasi-configuration, so I'd like to provide some convention over it.

I thought this feature could be implemented adding some custom resource loader to webpack at compile time, but so far I cannot figure out how.

Davide Cavestro
  • 473
  • 5
  • 13
  • the closest you can really get is by good use of the ng-template directive. It would not achieve exactly what you're looking for but I've seen good results with it. It provides a way of having more flexible / dynamic templates within a component. If what you're actually looking for is reuse of functionality across components, consider a directive instead. – bryan60 Jan 13 '19 at 20:26

1 Answers1

0

There is no built-in solution - but since you want to have compile time override posibility, why than how about writing shell script that will recursively copy everything from overrides to corresponding directories in main sources.

Another option would be to use dynami components https://blog.angularindepth.com/here-is-what-you-need-to-know-about-dynamic-components-in-angular-ac1e96167f9e

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • Automating the copy of overrides over the original templates wouldn't support multiple overrides for the same component (at different contexts) – Davide Cavestro Jan 14 '19 at 06:05