2

AsyncValidators requires Observable as retrun type. http request is Observale but my server returns true or false not {uniqeTitle:true} or null value as angular wants.

I have to create my own observable... with no luck.

Here what I have

static uniqeTitle(fieldControl: FormControl): Observable<any> {
    const subject = new Subject<any>();
    apiService.get('online-validation/')
        .subscribe(resp => {
            subject.next(resp?null:{uniqueTitle:true});
        });
    return subject;
}

Edit: I need complete!

1 Answer 1

1

Just use map to transform the value and return the mapped observable instead of creating a new one:

static uniqeTitle(fieldControl: FormControl): Observable<any> {

    return apiService.get('online-validation/')
        .map(resp => {
            return resp?null:{uniqueTitle:true});
        });

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.