Angular: Custom headers are ignored by $http and $resource. Why?

前端 未结 3 1563
夕颜
夕颜 2021-02-14 21:23

I\'m trying to access a REST service I don\'t control. First problem is that the service doesn\'t include a Access-Control-Allow-Origin header, which is a problem that, if I und

3条回答
  •  猫巷女王i
    2021-02-14 21:50

    While what you have is supposed to work according to the docs, my experience has been a bit different. To get around this issue, we did the following:

    Create a "base controller" that gets added to the page either on the body or html tag. In that controller, make the assignment using $http instead of $httpProvider. Because your base controller loads when the initial page loads, it is there for all other controllers and services that will run in your app.

    I don't know why this works and the proscribed method does not, and I'd love to see an answer to your question that is better than this work-around, but at least this can get you moving forward with development again.

提交回复
热议问题