Learn how to create a custom validator to check whether passwords match.
<H1>Password match</H1><formnovalidate AutoComplete= "Off"[Formgroup]= "Signupform"> <Divclass= "Form-field"> <label>Password:</label> <inputtype= "text"Formcontrolname= "Password"[(Ngmodel)]= "Signup.password"name= "Password"> </Div> <Divclass= "Form-field"> <label>Confirm Password:</label> <inputtype= "text"Formcontrolname= "Confirm"[(Ngmodel)]= "Signup.confirm"name= "Confrim"></Div></form>
this. Signupform = fb.group ({ password: [ ', validators.required ], confirm: [ ', [ validators.required, Confirmpasswordsthis. Signup) ] });
Confirmpasword Validator is just a function, also a curry function. So it means it is invoked when we pass the value ' Confirm ' password field.
So if we want to send extra params, we can use '. bind (Undefined, extraparam) '.
Bind to undefined context, would keep the context when it get invoked and then send a extraparam.
The extraparam would be ' passwords ' and the value later being passed in is ' confirm '.
Confirmpassword.ts:
Export function confirmpasswords (passwords, confirm) { const valid = passwords.password& & passwords.password = = = Confirm.value; return NULL : { confirmpassword: { false, ' passwrods is notthe ' Same" } };}
[Angular2 Form] Check Password Match