Learn how to create a custom validator to check whether passwords match.

<h1>password match</h1>
<form novalidate autocomplete="off" [formGroup]="signupForm">
<div class="form-field">
<label>Password:</label>
<input type="text" formControlName="password" [(ngModel)]="signup.password" name="password">
</div>
<div class="form-field">
<label>Confirm Password: </label>
<input type="text" formControlName="confirm" [(ngModel)]="signup.confirm" name="confrim"></div>
</form>
    this.signupForm = fb.group({
password: [
'',
Validators.required
],
confirm: [
'',
[
Validators.required,
confirmPasswords.bind(undefined, this.signup)
]
]
});

confirmPasword validator is just a function, also a curry function. So it means it will be 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, will keep the context when it get invoked, then send a extraParam.

The extraParam will be 'passwords' and the value later be passed in is 'confirm'.

confirmPassword.ts:

export function confirmPasswords(passwords, confirm) {
const valid = passwords.password&& passwords.password === confirm.value;
return valid ? null : {
confirmPassword: {
valid: false,
message: "Two passwrods are not the same"
}
};
}

[Angular2 Form] Check password match的更多相关文章

  1. C#实现的Check Password和锁定输错密码锁定账户

    C#实现的Check Password,并根据输错密码的次数分情况锁定账户:如果输入错误3次,登录账户锁定5分钟并提示X点X分后重试登录.如果5分钟后再次输入,累计输入错误密码累计达到5次.则账户会被 ...

  2. ux.form.field.Password 密码与非密码状态切换

    效果如图: 扩展源码: //扩展 //密码按钮扩展 //支持在密码与非密码之间切换 Ext.define('ux.form.field.Password', { extend: 'Ext.form.f ...

  3. [Angular2 Form] Create custom form component using Control Value Accessor

    //switch-control component import { Component } from '@angular/core'; import { ControlValueAccessor, ...

  4. [Angular2 Form] Nested formGroup, and usage of formGroupName

    We can nest formGorup: this.reactiveForm = fb.group({ username: [ '', [ Validators.required, Validat ...

  5. [Angular2 Form] Create Radio Buttons for Angular 2 Forms

    Using Radio Buttons in Angular 2 requires a basic understanding of forms as well as how their labels ...

  6. [Angular2 Form] Use RxJS Streams with Angular 2 Forms

    Angular 2 forms provide RxJS streams for you to work with the data and validity as it flows out of t ...

  7. [Angular2 Form] Understand the Angular 2 States of Inputs: Pristine and Untouched

    Angular 2’s ngModel exposes more than just validity, it even gives you the states of whether the inp ...

  8. [Angular2 Form] Group Inputs in Angular 2 Forms with ngModelGroup

    The ngModelGroup directive allows you to group together related inputs so that you structure the obj ...

  9. [Angular2 Form] Create and Submit an Angular 2 Form using ngForm

    Forms in Angular 2 are essentially wrappers around inputs that group the input values together into ...

随机推荐

  1. host---域名查询

    host命令是常用的分析域名查询工具,可以用来测试域名系统工作是否正常. 选项 -a:显示详细的DNS信息: -c<类型>:指定查询类型,默认值为“IN“: -C:查询指定主机的完整的SO ...

  2. 【Pycharm】【HTML】注释问题

    学习HTML中,遇到的注释前存在空行的问题: 只要找到Pycharm设置中:勾选去掉即可

  3. 南阳oj 士兵杀敌(二) 题目116 NYOJ 数据结构

     /*士兵杀敌(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:5 描写叙述 南将军手下有N个士兵.分别编号1到N.这些士兵的杀敌数都是已知的. 小工是南将军手下的军师, ...

  4. Linux下设置ip和主机名进行绑定

    1:输入命令gedit   /etc/hosts 这样你就打开了一个文本,然后在文本的末尾进行加入例如以下: ip地址                主机名 192.168.0.125       h ...

  5. linux下加入用户并赋予root权限

    1.加入用户.首先用adduser命令加入一个普通用户,命令例如以下: #adduser tommy //加入一个名为tommy的用户 #passwd tommy   //改动password Cha ...

  6. opencv之SURF图像匹配

    1.概述 前面介绍模板匹配的时候已经提到模板匹配时一种基于灰度的匹配方法,而基于特征的匹配方法有FAST.SIFT.SURF等.上面两篇文章已经介绍过使用Surf算法进行特征点检測以及使用暴力匹配(B ...

  7. 如何从mysql数据库中取到随机的记录

    如何从mysql数据库中取到随机的记录 一.总结 一句话总结:用随机函数newID(),select top N * from table_name order by newid() ----N是一个 ...

  8. OpenAL音频播放

    // // OpenALPlayer.m // live // // Created by lujunjie on 2016/11/5. // Copyright © 2016年 lujunjie. ...

  9. win10系统64位安装git后右键运行git bash here生成一个mintty.exe.stackdump文件后闪退解决方案

    在其他win10电脑上复制了一个null.sys文件,替换C:\Windows\System32\drivers\null.sys,搞定.

  10. 【Codeforces Round #432 (Div. 1) A】 Five Dimensional Points

    [链接]点击打开链接 [题意] 给你n个5维的点. 然后让你以其中的某一个点作为起点a. 另选两个点b,c. 组成向量a->b,a->c 如果所有的a->b和a->c的夹角都是 ...