私は角度2 RC2を使用しています。私は角2ルーターを私のカスタムExceptionHandlerクラスに注入する必要があります。無駄に@Injectを持つルータ:しかし、私は次のエラー角2 RC 2ルータをカスタムExceptionHandlerに注入する方法
Error: Error: Cannot resolve all parameters for 'ErrorHandler'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'ErrorHandler' is decorated with Injectable.
を取得し、私は民間のルータを飾ってみました。私はtypescriptを使用しているので、ここで@Inject属性が必要ではないと思います。この
import { ExceptionHandler } from '@angular/core';
import { Router } from '@angular/router';
export class ErrorHandler extends ExceptionHandler{
constructor(
private router: Router
){
super(null, null);
}
call(error, stackTrace = null, reason = null) {
console.log(error);
this.router.navigate(['/error']);
}
}
マイmain.tsは、なぜ私はこのエラーを取得しています。この
import { bootstrap } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';
import { provide, ExceptionHandler } from '@angular/core';
import { ErrorHandler } from './error-handler/error-handler';
import { HTTP_PROVIDERS } from '@angular/http';
import { ROUTER_PROVIDERS } from '@angular/router';
bootstrap(AppComponent, [
HTTP_PROVIDERS,
ROUTER_PROVIDERS,
provide(ExceptionHandler, {useClass: ErrorHandler})
]);
のように見えるように
私のカスタムexceptionHandlerのが見えますか? ExceptionHandlerのインスタンス化時にルータを注入できないのですか?
完全なソースコードはこちらです
https://github.com/harindaka/angular2-seed-typescript/tree/b368315ce6608085f3154a03bc53f0404ce16495
それがエラーを与えていない場合でも、 。私は、角度スローが例外をスローした後には動作しない(ナビゲートする)と思います。すべての角度機能が停止します。 –
@A_Singhそれは理にかなっています。次に、コードで未処理のエラーが発生した場合のコンテキストエラー情報を含むカスタムエラーページにリダイレクトする正しい方法は何ですか? – Harindaka
メッセージでカスタムアラートボックスを表示して、アプリをリロードするか選択してください。 –