Universal: No provider for InjectionToken RESPONSE!

Created on 17 Nov 2017  路  4Comments  路  Source: angular/universal

Note: for support questions, please use one of these channels: https://github.com/angular/universal/blob/master/CONTRIBUTING.md#question. This repository's issues are reserved for feature requests and bug reports. Also, Preboot has moved to https://github.com/angular/preboot - please make preboot-related issues there.

  • I'm submitting a ...
- [X ] bug report
- [ ] feature request
- [ ] support request => Please do not submit support request here, see note at the top of this template.
  • What modules are related to this Issue?
- [ ] aspnetcore-engine
- [X ] express-engine
- [ ] hapi-engine
  • Do you want to request a feature or report a bug?

Report a bug

  • What is the current behavior?

Error is thrown

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem by creating a github repo.

Trying to inject RESPONSE token into an Angular service like this:
@Inject(RESPONSE) private response: any

Also tried to use Injector:
const response = this.injector.get(RESPONSE);

  • What is the expected behavior?

Response object is injected.

  • What is the motivation / use case for changing the behavior?

Need access to response so I can write a cookie.

  • Please tell us about your environment:

  • Angular version: 5.0.0

  • Browser: all
  • Language: all
  • OS: all
  • Platform: all

  • Other information

I am able to inject REQUEST token successfully but not RESPONSE.

repro steps

Most helpful comment

Ended up solving this by changing:

res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req });

to:

res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req, res });

All 4 comments

https://github.com/Angular-RU/angular-universal-starter/blob/master/server.ts
try:

res.render('../dist/index', {
    req: req,
    res: res,
    providers: [
      {
        provide: REQUEST, useValue: (req)
      },
      {
        provide: RESPONSE, useValue: (res)
      }
    ]
  });

Could you please make a minimal repro

Ended up solving this by changing:

res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req });

to:

res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req, res });

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

A50 picture A50  路  5Comments

benrondeau picture benrondeau  路  5Comments

PatrickJS picture PatrickJS  路  5Comments

leon picture leon  路  4Comments

matthewharwood picture matthewharwood  路  4Comments