We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
platform-server
Yes
I'm trying to provide some tokens in server.ts, and use them in the application, for example:
server.get('*', (req, res, next) => { const { protocol, originalUrl, baseUrl, headers } = req; commonEngine .render({ bootstrap, documentFilePath: indexHtml, url: `${protocol}://${headers.host}${originalUrl}`, publicPath: browserDistFolder, providers: [ { provide: APP_BASE_HREF, useValue: baseUrl }, { provide: REQUEST, useValue: req }, { provide: TEST_TOKEN, useValue: 'huest'} ], }) .then((html) => res.send(html)) .catch((err) => next(err)); });
@Component({ selector: "app-root", standalone: true, imports: [CommonModule, RouterOutlet], templateUrl: "./app.component.html", styleUrls: ["./app.component.scss"], }) export class AppComponent implements OnInit { private platformId = inject(PLATFORM_ID); private injector = inject(Injector); ngOnInit(): void { if(isPlatformServer(this.platformId)) { const val = this.injector.get(TEST_TOKEN); <--------------------------------- const req = this.injector.get(REQUEST); <--------------------------------- console.log({val}) } } }
The problem is that it only works in normal build mode, if i use the serve mode, i get NullInjectorError: No provider error on the server side.
To double check this issue i created a new app from scratch using ng new but it didn't help.
https://github.com/newvladimirov/ng17-ssr-di-issue-2
No response
ng version
Angular CLI: 17.0.0 Node: 20.9.0 Package Manager: npm 10.1.0 OS: darwin arm64 Angular: 17.0.2 ... animations, common, compiler, compiler-cli, core, forms ... platform-browser, platform-browser-dynamic, platform-server ... router Package Version --------------------------------------------------------- @angular-devkit/architect 0.1700.0 @angular-devkit/build-angular 17.0.0 @angular-devkit/core 17.0.0 @angular-devkit/schematics 17.0.0 @angular/cli 17.0.0 @angular/ssr 17.0.0 @schematics/angular 17.0.0 rxjs 7.8.1 typescript 5.2.2 zone.js 0.14.2
The text was updated successfully, but these errors were encountered:
This is the same as: angular/angular-cli#26323 angular/angular-cli#26354
So I think this issue can be closed in favor of those other two.
Sorry, something went wrong.
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.
No branches or pull requests
Which @angular/* package(s) are the source of the bug?
platform-server
Is this a regression?
Yes
Description
I'm trying to provide some tokens in server.ts, and use them in the application, for example:
The problem is that it only works in normal build mode, if i use the serve mode, i get NullInjectorError: No provider error on the server side.
To double check this issue i created a new app from scratch using ng new but it didn't help.
Please provide a link to a minimal reproduction of the bug
https://github.com/newvladimirov/ng17-ssr-di-issue-2
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
No response
The text was updated successfully, but these errors were encountered: