5

I am using grunts ng-template to store the html templates in the $templateCache. The angular docs suggest that I can use the template like this:

myApp.component('myComponent', {
   templateUrl: 'templateId.html'
});

or like this:

 myApp.component('myComponent', {
   template: $templateCache.get('templateId.html')
});

What is the difference? I do not really like to inject $templateCache in every directive/component just to use this function. Is this about performance?

I have read this article: How much of a performance difference is between template and templateUrl Angularjs and if I am right then using a template (not templateUrl) is a little bit faster. Is this the only difference?

p u
  • 1,395
  • 1
  • 17
  • 30
Denis Chizhik
  • 141
  • 1
  • 7
  • templateUrl is always asynchronously called, though if it's already in templateCache, it shouldn't be much a difference. – Daniel Dec 02 '16 at 00:24
  • 1
    so there is a very good reason to use: $templateCache.get('templateId.html'), if you want to see the difference then use your directive in a popup or any container that uses a positioning service. If your directive affects the positioning of the container then it won't be loaded until the service has already calculated position. – Chris Stephens Aug 07 '17 at 17:27

0 Answers0