How to catch the exception when set form group control in angular?


I have a form group.

@Input() readonly formBuilder: FormBuilder;
public myFormGroup :FormGroup;
this.myFormGroup ={name: null});

Then in somewhere I want to patch the value by the code.

try {'some value');
} catch (e) {

However it failed to set up the value. My question is that I can’t catch the error. In the debugging I found it went to Subscriber.js and method

SafeSubscribe.prototype._tryOrUnsub = function(fn ,value) {
  try {, value); // hover it shows value = undefined
   catch (err) {
   throw err;

So I still don’t know what is wrong.


Figure it out by myself
The control is a kendo-datepicker; it need to convert a format then it works.

<kendo-datepicker [format]="'MM/dd/yyyy'" formControlName = "name"></kendo-datepicker>

And the ts code Date('some value));

So the trick is to add new Date().

But why I could not catch the error I still don’t know. For the moment it works out now anyway.

Answered By – Hello

Answer Checked By – Jay B. (AngularFixing Admin)

Leave a Reply

Your email address will not be published.