Tutorial by Examples

Angular 2 has two kinds of custom validators. Synchronous validators as in the first example that will run directly on the client and asynchronous validators (the second example) that you can use to call a remote service to do the validation for you. In this example the validator should call the ser...
constructor(fb: FormBuilder) { this.form = fb.group({ firstInput: ['', Validators.compose([Validators.required, CustomValidators.cannotContainSpace]), CustomValidators.shouldBeUnique], secondInput: ['', Validators.required] }); } Here we use the FormBuilder to crea...
There are 2 ways to set formBuilder controls parameters. On initialize: exampleForm : FormGroup; constructor(fb: FormBuilder){ this.exampleForm = fb.group({ name : new FormControl({value: 'default name'}, Validators.compose([Validators.required, Validators.maxLength(15)])) }); ...

Page 1 of 1