In the event of a TypeScript error, I am looking to send all of the component's
attribute values to a REST API
. It would greatly benefit me if I could access the component's context
(this
) in order to retrieve the values of all attributes within that component.
Is there a way to accomplish this? While ngDebugContext.view
contains the context, it is not accessible in PROD
mode.
[EDIT]
For instance, consider the following component
.
export class MyComponent implements OnInit{
constructor(service:BaseService){}
public first = 'first'; //.................... LINE 1
public second = ['a','b'];//.................. LINE 2
ngOnInit(){
let a = null;
console.log(a.name); //................... LINE 3
}
}
At LINE 3, a type error will occur and the error will be handled by the error handler service.
@Injectable()
export class ErrorHandlerService extends ErrorHandler {
...................
...................
handleError(error: Error | HttpErrorResponse) {
//I need to retrieve the values from LINE 1 & LINE 2 here..
}
}
Upon reaching the error handler, all information about MyComponent is lost, but I need to recover it.