Skip to content

Commit 22fa88d

Browse files
committed
chore: improve integration examples in README
1 parent 296889c commit 22fa88d

File tree

1 file changed

+25
-60
lines changed

1 file changed

+25
-60
lines changed

README.md

Lines changed: 25 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,37 @@ export const environment = {
8888
};
8989
```
9090

91-
Add an import for `BugSplatModule` to your `AppModule`:
91+
For Angular applications using standalone components, import and configure BugSplat directly in your `main.ts` file:
9292

93-
[app.module.ts](hhttps://github.com/BugSplat-Git/bugsplat-ng/blob/8c12d9b3544f2b618491467e6c40d84b6139eb2a/src/app/app.module.ts#L4)
9493
```typescript
95-
import { BugSplatModule } from 'bugsplat-ng';
94+
import { BugSplatLogger, BugSplatLogLevel, BugSplatModule } from 'bugsplat-ng';
95+
96+
bootstrapApplication(AppComponent, {
97+
providers: [
98+
// Required
99+
importProvidersFrom(
100+
BugSplatModule.initializeApp(environment.bugsplat)
101+
),
102+
// Optional
103+
{
104+
provide: ErrorHandler,
105+
useClass: MyAngularErrorHandler
106+
},
107+
{
108+
provide: BugSplatLogger,
109+
useValue: new BugSplatLogger(BugSplatLogLevel.info, console)
110+
}
111+
]
112+
})
113+
.catch(err => console.log(err));
96114
```
97115

98-
Add a call `BugSplatModule.initializeApp` in your AppModule's imports array, passing it your database, application, and version:
116+
Alternatively, add an import for `BugSplatModule` to your `AppModule`:
99117

100-
[app.module.ts](https://github.com/BugSplat-Git/bugsplat-ng/blob/8c12d9b3544f2b618491467e6c40d84b6139eb2a/src/app/app.module.ts#L31)
118+
[app.module.ts](hhttps://github.com/BugSplat-Git/bugsplat-ng/blob/8c12d9b3544f2b618491467e6c40d84b6139eb2a/src/app/app.module.ts#L4-31)
101119
```typescript
102-
...
120+
import { BugSplatModule } from 'bugsplat-ng';
121+
103122
@NgModule({
104123
imports: [
105124
BugSplatModule.initializeApp(environment.bugsplat)
@@ -241,60 +260,6 @@ Add a script to `package.json` that reads a `.env` file and calls `symbol-upload
241260

242261
For best results, please upload source maps for every released version of your application.
243262

244-
## 🚀 Standalone Components
245-
246-
For Angular applications using standalone components, you can integrate BugSplat without using NgModule. Import and configure BugSplat directly in your `main.ts` file:
247-
248-
```typescript
249-
import { enableProdMode, importProvidersFrom, ErrorHandler } from '@angular/core';
250-
import { bootstrapApplication } from '@angular/platform-browser';
251-
import { AppComponent } from './app/app.component';
252-
import { environment } from './environments/environment';
253-
import { BugSplatLogger, BugSplatLogLevel, BugSplatModule } from 'bugsplat-ng';
254-
import { MyAngularErrorHandler } from './app/my-angular-error-handler';
255-
256-
if (environment.production) {
257-
enableProdMode();
258-
}
259-
260-
bootstrapApplication(AppComponent, {
261-
providers: [
262-
importProvidersFrom(
263-
BugSplatModule.initializeApp(environment.bugsplat)
264-
),
265-
{
266-
provide: ErrorHandler,
267-
useClass: MyAngularErrorHandler
268-
},
269-
{
270-
provide: BugSplatLogger,
271-
useValue: new BugSplatLogger(BugSplatLogLevel.info, console)
272-
}
273-
]
274-
})
275-
.catch(err => console.log(err));
276-
```
277-
278-
Your custom error handler can be implemented the same way as in NgModule-based applications:
279-
280-
```typescript
281-
import { ErrorHandler, Injectable } from '@angular/core';
282-
import { BugSplat } from 'bugsplat-ng';
283-
284-
@Injectable()
285-
export class MyAngularErrorHandler implements ErrorHandler {
286-
constructor(public bugsplat: BugSplat) {
287-
// Optional configuration
288-
this.bugsplat.user = 'username';
289-
this.bugsplat.email = 'user@example.com';
290-
}
291-
292-
async handleError(error: Error): Promise<void> {
293-
return this.bugsplat.post(error, { description: 'Error from standalone component app' });
294-
}
295-
}
296-
```
297-
298263
## 🧑‍💻 Contributing
299264

300265
BugSplat loves open-source software! If you have suggestions on how we can improve this integration, please reach out to support@bugsplat.com, create an [issue](https://github.com/BugSplat-Git/bugsplat-ng/issues) in our [GitHub repo](https://github.com/BugSplat-Git/bugsplat-ng) or send us a [pull request](https://github.com/BugSplat-Git/bugsplat-ng/pulls).

0 commit comments

Comments
 (0)