Application becomes unresponsive after encountering an exception

前端 未结 4 1821
星月不相逢
星月不相逢 2020-11-28 09:24

How to tell Angular 2 to not block the whole application when it encounters an exception?

I\'m not sure if it\'s even possible, because Google didn\'t enlighten me o

4条回答
  •  独厮守ぢ
    2020-11-28 10:00

    On angular 2 final version, you can implement custom ErrorHandler (Angular 2 docs example):

    import {NgModule, ErrorHandler} from '@angular/core';
    
    class MyErrorHandler implements ErrorHandler {
      handleError(error) {
        // do something with the exception
      }
    }
    
    @NgModule({
      providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
    })
    class MyModule {}
    

提交回复
热议问题