I am writing an angular 2 validator function. I would like to return a plain object instead of an observable.
Here is my current implementation:
import {AbstractControl} from "@angular/common";
import {UserAccountService} from "../../useraccount/useraccount.service";
export function validateEmailAvailable(userAccountService: UserAccountService) {
return (control: AbstractControl)=> { //This returned lambda should itself return a plain object
return userAccountService.checkAvailability(control.value)
.map(res=> {
if (res.json() === true) {
return null;
}
else {
return {unavailable: true};
}
});
};
}
Can someone please explain how to properly use the RxJs operators in order to return either null
or {unavailable: true}
from the above but not an observable?
I would bet that this is not possible. This is the same as asking to ask an async function to return its value synchronously. Or returning a value in the present computed from values in the future. It is inherently contradictory. Promise 'operators' will always also return a promise, if you think about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With