Passing Data from to client with SSR not working #128

Closed
opened 2025-08-09 17:15:06 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @isaacrlevin on 3/15/2018

I followed the steps in the doc to setup SSR, and I want to test passing around the isHttpsRequest from Startup. I added this code to main.server.ts

{ provide: 'isHttp', useValue: params.data.isHttpsRequest }
and this in fetch-data.component.ts

 constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string, @Inject('isHttp') isHttp: boolean) {
    var foo = isHttp;
    http.get<WeatherForecast[]>(baseUrl + 'api/SampleData/WeatherForecasts').subscribe(result => {
      this.forecasts = result;
    }, error => console.error(error));
  }
}

When I publish to Azure, I get this error in console when I go to the Fetch Data route

Error: StaticInjectorError[isHttp]:
StaticInjectorError[isHttp]:
NullInjectorError: No provider for isHttp!

The reason this seems to happen is that isHttp is not provided in main.ts. I assumed that main.server.ts was used when in Production environment, is that not the case?

Here is a repo with the code
https://github.com/isaac2004/TestSSR

and the site deployed to Azure
https://test-ssr.azurewebsites.net/

I assume I am missing a stupid step, but the doc isn't clear. Any help would be greatly appreciated. Thanks

*Originally created by @isaacrlevin on 3/15/2018* I followed the steps in the doc to setup SSR, and I want to test passing around the isHttpsRequest from Startup. I added this code to main.server.ts `{ provide: 'isHttp', useValue: params.data.isHttpsRequest }` and this in fetch-data.component.ts ```` constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string, @Inject('isHttp') isHttp: boolean) { var foo = isHttp; http.get<WeatherForecast[]>(baseUrl + 'api/SampleData/WeatherForecasts').subscribe(result => { this.forecasts = result; }, error => console.error(error)); } } ```` When I publish to Azure, I get this error in console when I go to the Fetch Data route > Error: StaticInjectorError[isHttp]: StaticInjectorError[isHttp]: NullInjectorError: No provider for isHttp! The reason this seems to happen is that isHttp is not provided in main.ts. I assumed that main.server.ts was used when in Production environment, is that not the case? Here is a repo with the code https://github.com/isaac2004/TestSSR and the site deployed to Azure https://test-ssr.azurewebsites.net/ I assume I am missing a stupid step, but the doc isn't clear. Any help would be greatly appreciated. Thanks
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#128
No description provided.