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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745465624a4628904.html
评论列表(0条)