-
Notifications
You must be signed in to change notification settings - Fork 3k
$stateProvider requests template in templateURL with accept header as application/json which must be text/html #1287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
At first glance, a workaround might be to use an http interceptor |
This is the default $http behavior; ui-router is not setting the accept header. default Accept: See https://github.com/angular-ui/ui-router/blob/master/src/templateFactory.js#L85 |
Yes I understand . by default $http behavior accept header is application/json . But isnt that supposed to be text/html specially for templates which are served to application ? I mean in implementation of ui-router ? Cause almost all the cases in templateurl its always that a template would be an html only . so is it the only way for workaround for templateurl to be implemented by accept header application/json ? If yes . Can I just change this interceptor for one route state and not for all routes globally in interceptor by anyway ? and If no is there by any chance templateurl accept header can be changed manually or by defaults in ui-router can implement that (apart from http interceptor) ? |
This seems legit. Templates should probably be requested with |
Is there any thought going about this item ? Cause the reason is valid in case we are depending on a seamless backend which actually works with both api request and template request only based on accept headers . So we can achieve with a lot less code on backend . Rather than writing two different request handlers one for template another for api request . Just cause we dont request template with |
Add "Accept: text/html" to headers of $http.get invocation Closes issue angular-ui#1287
Fixed in #1341. |
In case you landed here due to a google search about this behavior: In the current version,
|
when we are actually requesting for a template url . The accept header is always "application/json" instead of "text/html"
I am currently Using nancy for generating both template and api request based on the content request type on accept headers .
Something like this
private dynamic Index(dynamic parameters)
{
List Students = NancyContext.Set().ToList();
return Negotiate.WithView("Index").WithModel(Students);
}
which basically when requested with 'application/json' returns json . And when requested with "text/html" then it returns the template with model . But since its requesting the template with 'application/json' . Its only returning json for the api request and not the template . Any workaround for to change the accept header to text/html instead of application/json for template url ?
The text was updated successfully, but these errors were encountered: