Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the angular registerControl() method for

I saw that angular form had the following method registerControl(), but I couldn't really understand its usage.
Does somebody have a nice explanation and a use case for it?

I have the feeling I'm missing something that could be useful.

Thx for your help.

Edit

I already read the angular explanation but couldn't understand it

like image 469
Raphaël Balet Avatar asked May 03 '26 07:05

Raphaël Balet


1 Answers

https://github.com/angular/angular/blob/13.1.x/packages/forms/src/model.ts

Basically, we add another control to the form without invoking a check on value and validity, so there won't be many cases when you want to use it.

The only case which comes to my mind atm is when you want to register multiple controls without invoking value and validity check and invoke such check manually after you add all controls which you need so it would be triggered only once.

For example if I use addControl 3 times it would invoke updateValueAndValidity 3 times. But if I first registerControl 3 times and then manually invoke updateValueAndValidity or SetControl etc. on those 3 new controls then it would be invoked only once.

To summarize, it seems to be more about optimization. I didn't create any check for it but to be honest I would be surprised if that lead to a lot of saved time.

like image 76
Adrian Sawicki Avatar answered May 06 '26 09:05

Adrian Sawicki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!