33var $compileMinErr = minErr ( '$compile' ) ;
44
55/**
6- * @ngdoc service
7- * @name $templateRequest
8- *
6+ * @ngdoc provider
7+ * @name $templateRequestProvider
98 * @description
10- * The `$templateRequest` service runs security checks then downloads the provided template using
11- * `$http` and, upon success, stores the contents inside of `$templateCache`. If the HTTP request
12- * fails or the response data of the HTTP request is empty, a `$compile` error will be thrown (the
13- * exception can be thwarted by setting the 2nd parameter of the function to true). Note that the
14- * contents of `$templateCache` are trusted, so the call to `$sce.getTrustedUrl(tpl)` is omitted
15- * when `tpl` is of type string and `$templateCache` has the matching entry.
16- *
17- * @param {string|TrustedResourceUrl } tpl The HTTP request template URL
18- * @param {boolean= } ignoreRequestError Whether or not to ignore the exception when the request fails or the template is empty
19- *
20- * @return {Promise } a promise for the HTTP response data of the given URL.
21- *
22- * @property {number } totalPendingRequests total amount of pending template requests being downloaded.
9+ * Used to configure the Accept header that is sent to the server when requesting a template.
2310 */
2411function $TemplateRequestProvider ( ) {
12+
13+ var httpOptions ;
14+
15+ /**
16+ * @ngdoc method
17+ * @name $templateRequestProvider#httpOptions
18+ * @description
19+ * The options to be passed to the $http service when making the request.
20+ * You can use this to override options such as the Accept header for template requests.
21+ *
22+ * The {$templateRequest} will set the `cache` and the `transformResponse` properties of the
23+ * options if not overridden here.
24+ *
25+ * @param {string= } value new value for the {@link $http} options.
26+ * @returns {string|self } Returns the {@link $http} options when used as getter and self if used as setter.
27+ */
28+ this . httpOptions = function ( val ) {
29+ if ( val ) {
30+ httpOptions = val ;
31+ return this ;
32+ }
33+ return httpOptions ;
34+ } ;
35+
36+ /**
37+ * @ngdoc service
38+ * @name $templateRequest
39+ *
40+ * @description
41+ * The `$templateRequest` service runs security checks then downloads the provided template using
42+ * `$http` and, upon success, stores the contents inside of `$templateCache`. If the HTTP request
43+ * fails or the response data of the HTTP request is empty, a `$compile` error will be thrown (the
44+ * exception can be thwarted by setting the 2nd parameter of the function to true). Note that the
45+ * contents of `$templateCache` are trusted, so the call to `$sce.getTrustedUrl(tpl)` is omitted
46+ * when `tpl` is of type string and `$templateCache` has the matching entry.
47+ *
48+ * If you want to pass custom options to the `$http` service, such as setting the Accept header you
49+ * can configure this via {@link $templateRequestProvider#httpOptions}.
50+ *
51+ * @param {string|TrustedResourceUrl } tpl The HTTP request template URL
52+ * @param {boolean= } ignoreRequestError Whether or not to ignore the exception when the request fails or the template is empty
53+ *
54+ * @return {Promise } a promise for the HTTP response data of the given URL.
55+ *
56+ * @property {number } totalPendingRequests total amount of pending template requests being downloaded.
57+ */
2558 this . $get = [ '$templateCache' , '$http' , '$q' , '$sce' , function ( $templateCache , $http , $q , $sce ) {
59+
2660 function handleRequestFn ( tpl , ignoreRequestError ) {
2761 handleRequestFn . totalPendingRequests ++ ;
2862
@@ -45,12 +79,10 @@ function $TemplateRequestProvider() {
4579 transformResponse = null ;
4680 }
4781
48- var httpOptions = {
49- cache : $templateCache ,
50- transformResponse : transformResponse
51- } ;
52-
53- return $http . get ( tpl , httpOptions )
82+ return $http . get ( tpl , extend ( {
83+ cache : $templateCache ,
84+ transformResponse : transformResponse
85+ } , httpOptions ) )
5486 [ 'finally' ] ( function ( ) {
5587 handleRequestFn . totalPendingRequests -- ;
5688 } )
0 commit comments