2017-01-13 9 views
3

角度2を使用してイオン2ハイブリッドアプリケーションを作成しようとしています。その中でErrorHandlerインターフェイスを実装しましたが、エラーが発生しても何も起こりません。それがエラーハンドラを実装するための正しい方法であれば、私は知らないこれこれが、ここで私のアプリモジュールコードイオン2の例外処理が機能していませんか?

import { NgModule, ErrorHandler} from '@angular/core'; 
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular'; 
import { MyApp } from './app.component'; 
import { Page1 } from '../pages/page1/page1'; 
import { Page2 } from '../pages/page2/page2'; 
import { homePage } from '../pages/home/homePage'; 
import { MyPage } from '../pages/my-page/my-page'; 
import { FormsPage } from '../pages/forms/forms'; 
import { SharedData } from '../providers/shared-data'; 
import {MyExceptionHandler} from '../validators/myhandler'; 


@NgModule({ 
    declarations: [ 
    MyApp, 
    Page1, 
    Page2, 
    homePage, 
    MyPage, 
    FormsPage 

    ], 
    imports: [ 
    IonicModule.forRoot(MyApp) 
    ], 
    bootstrap: [IonicApp], 
    entryComponents: [ 
    MyApp, 
    Page1, 
    Page2, 
    homePage, 
    MyPage, 
    FormsPage 

    ], 
    providers: [{provide: ErrorHandler, useClass: IonicErrorHandler},SharedData] 
}) 
export class AppModule {} 

私appcomponent

import { NgModule,Component, ViewChild,ErrorHandler} from '@angular/core'; 
//import {provide} from '@angular2/core'; 
import { Nav, Platform, } from 'ionic-angular'; 
import { StatusBar, Splashscreen } from 'ionic-native'; 

import { Page1 } from '../pages/page1/page1'; 
import { Page2 } from '../pages/page2/page2'; 
import{homePage} from '../pages/home/homePage'; 
import { FormsPage } from '../pages/forms/forms'; 
import {MyExceptionHandler} from '../validators/myhandler'; 
@NgModule({ 
    providers: [{provide: ErrorHandler, useClass: MyExceptionHandler}] 
}) 

@Component({ 
    templateUrl: 'app.html' 

}) 
export class MyApp { 
    @ViewChild(Nav) nav: Nav; 
    rootPage: any = homePage; 
    pages: Array<{title: string, component: any}>; 

    constructor(public platform: Platform) { 
    this.initializeApp(); 

    // used for an example of ngFor and navigation 
    this.pages = [ 
     { title: 'gotohomepage', component: homePage }, 
     { title: 'gotopage1', component: Page1 }, 
     { title: 'gotopage2', component: Page2 }, 
     { title: 'forms', component: FormsPage } 
    ]; 

    } 

    initializeApp() { 
    this.platform.ready().then(() => { 
     // Okay, so the platform is ready and our plugins are available. 
     // Here you can do any higher level native things you might need. 
     StatusBar.styleDefault(); 
     Splashscreen.hide(); 
    }); 
    } 

    openPage(page) { 
    // Reset the content nav to have just this page 
    // we wouldn't want the back button to show in this scenario 
    this.nav.setRoot(page.component); 
    } 
} 
あるイオン2

で私の最初のアプリです

と私のハンドラのページ

import { Component,ViewChild,ErrorHandler } from '@angular/core'; 

export class MyErrorHandler extends IonicErrorHandler { 
    handleError(err: any): void { 
    super.handleError(err);//call parent handleError 
} 

    ionViewDidLoad() { 
    alert('ionViewDidLoad FormsPage'); 
    } 
} 

おかげで、

答えて

3
  1. カスタムクラスでhandleError関数をオーバーライドする必要があります。

  2. handleError(err: any): void { super.handleError(err);//call parent handleError // do something with the error }はまた、あなたはあなたのprovider.Check hereとしてIonicErrorHandlerを設定してthis is the github link

あなたは、プロバイダの配列を設定することができ、次のいずれかまたは私がしようと提案し

providers: [{provide: ErrorHandler, useClass: MyExceptionHandler },SharedData] 

代わりにIonicErrorHandlerを拡張してください。

import { Component,ViewChild,ErrorHandler } from '@angular/core'; 

export class MyExceptionHandler extends IonicErrorHandler implements ErrorHandler{ 
handleError(err: any): void { 
super.handleError(err);//call parent handleError 
// do something with the error 
} 
} 
+0

"実行時エラー MyErrorHandlerのすべてのパラメータを解決できません:(?)。" –

+0

IonicErrorHandlerをインポートしましたか? –

+0

また、ionicViewLoadライフサイクルフックウィントエラーハンドラで呼び出すことができます。それはコンポーネントではありません –

関連する問題