Improve this Doc View Source $templateRequest

From Get docs
< Service components in ngAngularjs/docs/1.8/api/ng/service/$templaterequest

Improve this Doc View Source $templateRequest

  1. $templateRequestProvider
  2. service in module ng


The $templateRequest service runs security checks then downloads the provided template using $http and, upon success, stores the contents inside of $templateCache. If the HTTP request fails or the response data of the HTTP request is empty, a $compile error will be thrown (the exception can be thwarted by setting the 2nd parameter of the function to true). Note that the contents of $templateCache are trusted, so the call to $sce.getTrustedUrl(tpl) is omitted when tpl is of type string and $templateCache has the matching entry.

If you want to pass custom options to the $http service, such as setting the Accept header you can configure this via $templateRequestProvider.

$templateRequest is used internally by $compile, $route, and directives such as ngInclude to download and cache templates.

3rd party modules should use $templateRequest if their services or directives are loading templates.


$templateRequest(tpl, [ignoreRequestError]);


Param Type Details
tpl stringTrustedResourceUrl The HTTP request template URL



boolean Whether or not to ignore the exception when the request fails or the template is empty


Promise a promise for the HTTP response data of the given URL.


  • === totalPendingRequests ===

    total amount of pending template requests being downloaded.

© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 3.0.$templateRequest