-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
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
[Angular] Init of rg4js doesn't work correctly if it's in constructor #383
Comments
Hi @DownloadHelper, Which version of Angular are you using? I managed to get this to work, but with the version number and API key stored in an environment object. Thanks, |
Hi @samuel-holt Thank you for your response ! I'm using Angular 11.0.6. fetch('urlToGetMyConfig')
.then(response => response.json())
.then(config => {
if (environment.production) {
enableProdMode();
}
console.log("config loaded");
platformBrowserDynamic([{ provide: APP_CONFIG, useValue: config}])
.bootstrapModule(AppModule)
.catch(err => console.error(err));
}) But if we write some code before an angular class, that is execute before Angular lifecycle. console.log("this is execute before config loaded");
export class RaygunErrorHandler implements ErrorHandler {
constructor(){
console.log("this is execute after config loaded");
}
handleError(e: any) {
console.error(e);
rg4js('send', {
error: e,
});
}
} That's why i need to init the rg4js into my constructor. |
Hi @DownloadHelper, This is not a common use case, and not one I've come across before. What's the reason for loading the config values from a server? One avenue that you could look at might be a factory provider. See this blog post for how to handle async providers. Regards, |
Hi @samuel-holt, I need to load my config in another file than environment.ts because i have to respect a CI/CD principe : "build once deploy everywhere". If i use environment.ts file, i have to create something like environment.pre.ts and environment.prod.ts, so to deploy in pre we have to build like "ng build --pre" and to deploy in prod we have to build like "ng build --prod". Thank you for the link to handle async proviers. Unfortunalty, i already tried and this is the same result. With my main.ts i load config first and then load and bootstrap my app (AppModule). But when we write some js ABOVE Angular class/component : it seems to be run before all Angular lifecycle. Regards, |
Hi @DownloadHelper, One idea I had was to use the V1 API to initialize Raygun4JS synchronously - this could be done outside of the Angular sphere (i.e. in the For example:
Let me know if that could work for you. Thanks, |
Hello there. This is not working in all the cases. global Raygun variable might not be assigned in time and the fetch will be executed faster. Eventually you will get the message like 'Raygun is not defined' I have a screaming to you, dear developers. STOP PUSHING YOUR LINE, please. I see numerous issues where people complain on that they can't define api key when they want. give just an option for some who really need it to initialize raygun asynchronously. Capture all errors as you do, Do not react in that one time setup in onLoadHandler. What the matter of all the setup if there is no API key?
|
If you use these setup instructions, does it work for you? |
Hi !
The standard init of rg4js for Angular ErrorHandler working good :
But that doesn't work correctly if we move the init into a constructor :
Do you have an idea? I would need this to get my configuration and my apiKey from an Angular service.
Thank you !
The text was updated successfully, but these errors were encountered: