Angular2 RC5+ installation

I’m having trouble integrating Raven with an angular2 project. I’ve followed the provided instructions, but they seem a bit out of date. Firstly provide is deprecated in RC6 and has been removed in RC7 (which we are now using). Also the instructions seem to be geared around the “old” way of bootstrapping a project. We’re now using modules and I can’t see how to add the Raven exception handler. I tried as follows, and although on RC6 this didn’t throw any errors, it also didn’t log anything to Sentry. Furthermore on RC7 provide has been removed, and this way then failed:

var Raven = require('raven-js');
Raven
    .config('my_dsn')
    .install();

class RavenExceptionHandler {
    call(err: any) {
        Raven.captureException(err.originalException);
    }
}
....
export class SharedModule {
    static forRoot(): ModuleWithProviders {
        return {
            ngModule: SharedModule,
            providers: [
                provide(ExceptionHandler, {useClass: RavenExceptionHandler})
            ],
        }
    }
}

Now Angular2 Final released :tada:

this document setting is not working, because @wengole said provide deprecated and ExceptionHandler rename ErrorHandler commit .

I work this code.

import * as Raven from 'raven-js';
Raven.config(environment.sentryUrl).install();
class RavenExceptionHandler {
  call(err: any) {
    Raven.captureException(err.originalException);
  }
}

---------

@NgModule({
  imports: [ ~~~ ],
  declarations: [ ~~~~~ ],
  providers: [
    { provide: ErrorHandler, useClass: RavenExceptionHandler}
  ]
});

I’ve submitted a PR with the documentation fix.

https://github.com/getsentry/raven-js/pull/732

1 Like