2

I just need to put a custom path in templateURL

@Component({ 
  selector: 'hero-detail', 
  templateUrl: BASE_TEMPLATE_PATH + 'hero-detail.component.html',
  styleUrls: ['hero-detail.component.css']
})

I tried a lot of things indicated in this post

Angular2 how to set templateUrl base path

but no one worked for me, tried many times to implement something from that pot but no success, and the post don't have enough information where put the variables, can you guys give some light ?

  • Possible duplicate of [Angular2 how to set templateUrl base path](https://stackoverflow.com/questions/36797977/angular2-how-to-set-templateurl-base-path) – Kyle Krzeski Sep 25 '17 at 19:01

1 Answers1

0

My idea can you have base path input hidden field in index.html like,

<input type="hidden" id="hdnTemplate" value="http://example.com/app/modules/templates" />
@Component({
  selector: 'hero-detail',
  templateUrl: function() { return $('#hdnTemplate').val()+'/hero.detail.component.html'}()
})
Punith
  • 191
  • 1
  • 5
  • that solutions ins't performatic, needs something like a global variable or some kind of configuration in some file configuration like tsconfig.app.json – Felipe Luis Mendes Sep 26 '17 at 18:32
  • This won't work with newer Angular versions. `templateUrl` will be replaced by a require call by angular cli internally. The require argument must be a string literal. Otherwise webpack cannot resolve the dependency. (Yes, the template is in fact a dependency like other imports later) – fishbone Aug 22 '18 at 06:34