Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

angular directive templateUrl should allow "text/html" Accept and content-type headers #6860

Closed
geoidesic opened this issue Mar 26, 2014 · 6 comments

Comments

@geoidesic
Copy link

templateUrl is generally going to be expecting to receive HTML back from the server. To inform the server of that (according to RESTful best practices) it would be useful to be able to specify the headers for the $http request that fetches the actual template.

The default being used by angularJS is "application / json". It would be useful to be able to specify "text/html" instead for templateUrl. In addition I submit that should be the default for any request that expects HTML back from the server.

@caitp
Copy link
Contributor

caitp commented Mar 26, 2014

hmm... well it does make sense. Care to send a PR?

@tbosch tbosch self-assigned this Mar 26, 2014
@tbosch tbosch added this to the Backlog milestone Mar 26, 2014
@tbosch tbosch removed their assignment Mar 26, 2014
@shawnbissell
Copy link

I think the content-type for the templates should be "text/ng-template" so that it matches the mime type already defined for the script directive. https://docs.angularjs.org/api/ng/directive/script
The problem with using "text/html" is that templates are almost always fragments of html and contain angular specific markup which means they do not validate as HTML and are not renderable in a browser by themselves.

@btford btford removed the gh: issue label Aug 20, 2014
@jammnrose
Copy link

I'm actually running into a real use-case with this issue, where it would not only be more correct, but actually useful. The problem that we have is that our server can send back our login page HTML (as text/html) if a user stays on a page for too long before navigating and causing template(s) to be loaded. This results in the login page being injected where the template should be. The way we're going to work around it is with an http interceptor, setting the Accept header to text/ng-template conditionally for our template requests (based on our URL patterns). Our server can then return an appropriate HTTP/415 status code if it can't serve the template.

I think that for directives and routes it could be useful, as discussed, to allow the setting of HTTP headers, and probably at least setting a default value for Accept of text/ng-template.

@shawnbissell completely agree. Was just discussing this with a co-worker. It's definitely wrong to be serving templates as text/html, as they are just HTML fragments.

@dmoscrop per http://tools.ietf.org/html/rfc6648 "X-" based headers are now deprecated. Basically, as long as you choose a sufficiently unique and meaningful mime type, you're free to invent your own.

@dougmoscrop
Copy link

@jammnrose retracted! good to know

@giosh94mhz
Copy link

👍 faced the same issue.

@toninofox
Copy link

Same Issue following the REST Convention.
Adding .html as suffix of the templateUrl parameter it works but it is a little bit confusing to understand that it is a endpoint...

luckycadow added a commit to luckycadow/angular.js that referenced this issue May 13, 2015
Set the `Accept` header on HTTP requests for templates to `text/html, text/ng-template`.
Previously the default request headers sent by `$http` were used.

Closes angular#6860
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Oct 28, 2015
It is now possible to configure the Accept header for template requests.
If a value is configured then this will override only the Accept property
of the headers that are passed.
If no value is configured then the request will use the default $http
Accept header.

Thanks to @luckycadow for help on this feature

Closes angular#11868
Closes angular#6860
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Oct 28, 2015
It is now possible to configure the Accept header for template requests.
If a value is configured then this will override only the Accept property
of the headers that are passed.
If no value is configured then the request will use the default $http
Accept header.

Thanks to @luckycadow for help on this feature

Closes angular#11868
Closes angular#6860
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Oct 28, 2015
It is now possible to configure the options sent to $http for template requests.
If no value is configured then the request will use the default $http options.

Thanks to @luckycadow for help on this feature

Closes angular#11868
Closes angular#6860
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Oct 28, 2015
It is now possible to configure the options sent to $http for template requests.
If no value is configured then the request will use the default $http options.

Thanks to @luckycadow for help on this feature

Closes angular#11868
Closes angular#6860
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.