I have object which is property are arrays of objects:
messages = {
authentication: [
{ type: 'signinFail', message: 'Login Fail! Wrong password or email.' }
],
requiredText: [
{ type: 'required', message: 'This field is required.' }
],
email: [
{ type: 'required', message: 'Email is required.' },
{ type: 'email', message: 'Email has an incorrect format.' }
],
confirm_password: [
{ type: 'required', message: 'Password confirmation is required.' },
{ type: 'areNotEqual', message: 'Password mismatch' }
],
password: [
{ type: 'required', message: 'Password is required' },
{ type: 'minlength', message: 'Password must contain 5 or more characters.' },
{ type: 'pattern', message: 'Your password must contain at least one uppercase, one lowercase, and one number' }
]
};
I need to get massage from structire above while I provide two strings, subject and type to function that i created:
getMessage(subject, type) : string {
return this.messages[subject][type];
}
For example, if I provide:
subject = "confirm_password"
type = "minlength"
I expect to get this message from the getMessage function:
'Password must contain 5 or more characters.'
but I get error undefined.
Any idea how to get the desired message if I provide the subject and type?