typescript - Promise's reject is throwing Error in angular 2/4 -


i have defined async validator function this.

static shouldbeunique(control: abstractcontrol): promise<validationerrors | null> {     return new promise((resolve, reject) => {         settimeout(() => {             if (control.value === 'some_text') {                 resolve({ shouldbeunique: true });             }             reject(null);         }, 2000);     }); } 

its throwing below error (may on reject)

cannot read property 'ngoriginalerror' of null

how rid of error? thanks

plnkr : https://embed.plnkr.co/vshxgkimguwehy8neyxu/

generally if reject promise should better reject error

reject(new error('user not vikash (whatever descriptive message went wrong)')); 

edit since trying implement async validator need resolve promise null not reject indicate validation ok.

static shouldbeunique(control: abstractcontrol): promise<validationerrors | null> {     return new promise((resolve, reject) => {         settimeout(() => {             if (control.value === 'some_text') {               resolve({ shouldbeunique: true });             } else {               resolve(null); // resolve             }         }, 2000);     }); } 

demo


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -