-2

I have an angular application. From frontend I can set some value. This value is something like config, which can be changed. It is simple string variable. How to attach this config to each REST request ? I ask mainly about approach.

Maybe pass it via headers is good idea ?

Haskell Fun
  • 299
  • 4
  • 13

2 Answers2

0

For angular 1.x, write an Interceptor:

For purposes of global error handling, authentication, or any kind of synchronous or asynchronous pre-processing of request or postprocessing of responses, it is desirable to be able to intercept requests before they are handed to the server and responses before they are handed over to the application code that initiated these requests

For angular 2.x / 4.x, RequestOptions should be the key to solve your problem. Set base url for angular 2 http requests

I'm using angular2, my solution is create a Service and inject "Http" dependency, then write two methods "get", "post", these methods add an entry to header before calling "Http", in other component / service, I just inject this Service class, then call its "get" or "post".

kite.js.org
  • 1,599
  • 10
  • 11
0

Your code should be somewhat like this If your working in angular 1.3 or less The data should be sent as body data to server

var basecall = Restangular.all('url');
bascall.post($scope.config).then(function(data){

 })
Vignesh
  • 1,140
  • 1
  • 9
  • 17