I'm using DevExtreme components, and this is where the callback function gets called in the html:
<dxi-validation-rule type="custom"
[validationCallback]="validationCallback"
message="Email exists">
</dxi-validation-rule>
In the ts file:
validationCallback (e) {
const x = this.userService.getUserByEmail(e.value);
x.subscribe(ref => ref.email != null ? true : false);
return x;
}
Service code:
getUserByEmail(email: string): Observable<User> {
return this.afs
.collection<User>('users', ref => ref.where('email', '==', email))
.snapshotChanges()
.map(
users => {
const user = users[0];
if (user) {
const data = user.payload.doc.data() as User;
const id = user.payload.doc.id;
console.log('found: ' + data.email);
return { id, ...data };
} else {
return null;
}
}
);
}
Problem with that code is that I get:
Cannot read property 'getUserByEmail' of undefined
Basically means I'm trying to access this.userService
which is out of the function's scope. How would I be able to access an external function to validate e-mail in this situation?