Angular2 get existing validators of a formcontrol

krishna picture krishna · Apr 6, 2017 · Viewed 16.1k times · Source

Lets say

surname = new FormControl('', [Validators.required, Validators.minLength(2)]);

At some point depending on the situation I may add or delete any validators on surname control.

At the end How do I know what validators exists on surname control? I couldn't find any thing in documentation nor by dumping the control into console

Something like

surname.getValidators() should return - ['required', 'minLength']

Answer

Günter Zöchbauer picture Günter Zöchbauer · Apr 6, 2017

Reading validators from a control is currently not supported

See also https://github.com/angular/angular/issues/13461