Within my accountService module, there is a dialog prompt that requests the user's username and password, returning a promise. If the user clicks on close instead of dismissing the dialog box and the validators require the input data before allowing the close action, then I need to log in with that data and return an observable result.
loginModal() : boolean {
this.dpDialogService.input(
'Login',
[
{
label: 'Username/Email',
form: 'username',
data: '',
validators: [Validators.required],
validatorMsg: 'Username is required.'
},
{
label: 'Password',
form: 'password',
data: '',
validators: [Validators.required],
validatorMsg: 'Password is required.',
type: 'password'
},
]
).then(
close => {
this.login({username: close.username.value, password: close.password.value}).subscribe(
loginResult => {
return true;
},
errorResult => {
this.dpDialogService.error('Invalid username/password.');
return false;
}
)
},
dismiss => {
return false;
}
);
}
I am looking for a way to return a boolean value from this function. It seems like using a promise might be necessary, but I'm unsure how to handle it given the nested structure.