javascript - Why this Angular 4 custom validator return a Promise or an Observable? What is the exact logic? -
i new in angular 4 , not javascript\typescript , have following doubt example found in tutorial.
it related implementation of custom form validator doubts more observable , promise objects.
so have this:
import {form, formcontrol} '@angular/forms'; import {observable} 'rxjs/observable'; export class customvalidators { static asyncinvalidprojectname(control: formcontrol): promise<any> | observable<any> { const promise = new promise((resolve, reject) => { settimeout(() => { if (control.value === 'testproject') { resolve({'invalidprojectname': true}); } else { resolve(null); } }, 2000); }) return promise; } }
the asyncinvalidprojectname() method implements logic of custom validator.
my doubts are:
1) seems me method can return promise object or observable object.
why? seems me return promise object represents if input in form valid or not. why in signature seems can return observable?
2) represents promise object , difference observable? (from know observable used react event change)
Comments
Post a Comment