question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dependency injection not working for custom RequestOptions class when making a post request to remote url

See original GitHub issue

I’m submitting a … (check one with “x”)

[x ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

I have a CustomRequestOptions class that extends the RequestOptions class which I want to be injected with some values from a config class that I need for customising the headers and request URL etc. This is working fine with GET requests but when I come to do a POST request I am experiencing some unexpected behaviour. The api I am calling is on a different domain so CORS browser policy is issuing a pre-flight OPTIONS request which is expected but the RequestOptions code is kicking in twice and dependency injection of the config does not work when my POST request is actually executed (the second time the RequestOptions code kicks in…

Expected/desired behavior

I am expecting to be able to dependency inject an extended RequestOptions class when making a POST request. As to whether the RequestOptions should be called twice I am unsure what the teams desired behaviour is…

Reproduction of the problem If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).

Reproduction is here: http://plnkr.co/edit/Bcr0RfJIf65TXOkgwgs2 see console log for outputs.

Please tell us about your environment:

  • Angular version: 2.0.0-rc.6
  • Browser: [all ]
  • Language: [ TypeScript 2.0 ]

Cross ref: http://stackoverflow.com/questions/39359060/angular2-rc6-custom-requestoption-behaviour-when-cors-post-request

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:25 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
alxhubcommented, Apr 1, 2017

Overriding merge in RequestOptions is not a supported usage of the API. There will be a much better way of manipulating request options in upcoming HTTP APIs (interceptors).

1reaction
haia212commented, Feb 3, 2017

@mattheiler I am having the same issue and came to the same conclusion. How did you workaround this issue ? @DzmitryShylovich what would be the (angular) way to change an http header ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency Injection with classes other than a Controller class
I tried hunting down where it happens in the Controller object source code, but it gets kinda crazy in there. I do know...
Read more >
Communicating with backend services using HTTP - Angular
You can then inject the HttpClient service as a dependency of an application class, as shown in the following ConfigService example. app/config/config.service.
Read more >
Complete Guide to Axios HTTP Client - Reflectoring
In this article, we will understand Axios and use its capabilities to make different types of REST API calls from JavaScript applications.
Read more >
Core HTTP API • Angular - codecraft.tv
We inject the Http client library into our classes, it's a dependency that needs to be configured in ... How to send custom...
Read more >
Dependency injection in ASP.NET Core | Microsoft Learn
A class can create an instance of the MyDependency class to make use of its ... Dependency injection addresses these problems through:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found