I recently figured out my html content consists of
{{employer.userdata.firstname}}
while there was an implementation change to employer.firstname
on class level. The bad side effect was that the wrong binding did not throw any kind of exception and only after some long time of debugging I figured out that employer.userdata == undefined
So I was thinking if there is a chance to implement some generic Exception/ErrorHandler to provide useful information on the console. I tried this approach with
import { ErrorHandler } from '@angular/core';
export class MyErrorHandler extends ErrorHandler {
constructor() {
super(true);
}
handleError(error) {
console.log(`MyErrorhandler: ${error}`);
super.handleError(error);
}
}
and in my app.module.ts
@NgModule({
providers: [{ provide: ErrorHandler, useClass: MyErrorHandler }]
})
but still there is no console-log. Any hints how to do it 'properly' ?
EDIT:
From the responses I see that my sample was too simple :-/ I rechecked my code and I have had the code like:
<input class="form-control" type="text" id="firstName"
formControlName="firstName"
[formControl]="form.controls['firstName']"
[(ngModel)]="employer.userdata.firstname">
after changing it to employer.fistname
the whole code runs perfectly. I only got an hint after I performed a manual doCheck()
which finally throw the Exception. I guess the Exception was thrown already before and somewhere swallowed during the init phase of the complete control ==> how to NOT let is swallow? My approach didn't help :-/