admin管理员组文章数量:1426280
I'm deploying my Angular application in a web server, where the app may live at http://localhost:8080/app-name
, or /
, or some other URL. I do not have any guarantees about the absolute path - sometimes the call may need to go to /app-name/foo
, sometimes to /foo
, sometimes to /foobars/foo
. In other words, there is a moving part: /app-name
, (empty)
, /foobars
in samples above. Also known as context path.
I know I can use <base>
for HTML. I can wrap $http
or configure Restangular to prepend context path for all calls.
But there still are cases that I don't yet know how to address. For instance, whenever directive uses a template, it is loaded via bare $http
as well.
How can I get $http
to always use some specific base path for all requests?
I'm deploying my Angular application in a web server, where the app may live at http://localhost:8080/app-name
, or http://foobars./
, or some other URL. I do not have any guarantees about the absolute path - sometimes the call may need to go to /app-name/foo
, sometimes to /foo
, sometimes to /foobars/foo
. In other words, there is a moving part: /app-name
, (empty)
, /foobars
in samples above. Also known as context path.
I know I can use <base>
for HTML. I can wrap $http
or configure Restangular to prepend context path for all calls.
But there still are cases that I don't yet know how to address. For instance, whenever directive uses a template, it is loaded via bare $http
as well.
How can I get $http
to always use some specific base path for all requests?
- According to the docs you can add a request transform to modify the request configuration object. Unfortunately, I couldn't find too much info describing the request configuration object, but after taking a quick look through the source, it appears that the url being requested is ing from that config object. – Jason Commented Oct 9, 2013 at 20:57
1 Answer
Reset to default 2You will want to configure the $httpProvider to use an Interceptor that modifies the config that the call to $http will use.
See the Interceptors section here: http://docs.angularjs/api/ng.$http
This will allow you to control your contextual path in any way you need for all $http calls.
本文标签: javascriptAngular JS How to set context path for all calls through httpStack Overflow
版权声明:本文标题:javascript - Angular JS: How to set context path for all calls through $http? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745465623a2659520.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论