项目作者: jimmylin212

项目描述 :
An Angular directive that compare input from reactive form.
高级语言: TypeScript
项目地址: git://github.com/jimmylin212/ngx-equalsto.git
创建时间: 2019-06-27T03:34:01Z
项目社区:https://github.com/jimmylin212/ngx-equalsto

开源协议:MIT License

下载


ngx-Equalsto

pipeline status
coverage report

Angular directive to check if 2 or more input values are same in the reactive form. If not, then mark the form control invalid with error. This is widely use with form that have password and password confirm.

Installation

npm install --save ngx-equalsto

Import NgxEqualsto in your app module.

  1. import { NgxEqualstoModule } from 'ngx-equalsto';
  2. @NgModule({
  3. imports: [
  4. NgxEqualstoModule,
  5. ],
  6. })
  7. export class AppModule {}

Usage

This directive work with reactive form only. You need to mention the form control that equals to in equalsTo directive.

Here is the example of how to use in COMP.component.ts and COMP.component.html.

  1. export class AppComponent implements OnInit {
  2. exampleForm: FormGroup;
  3. constructor(private formBuilder: FormBuilder) {}
  4. ngOnInit() {
  5. this.exampleForm = this.formBuilder.group({
  6. password: null,
  7. passwordConfirm: null,
  8. });
  9. }
  10. }
  1. <form [formGroup]="exampleForm">
  2. <input formControlName="password">
  3. <input formControlName="passwordConfirm" equalsTo="password">
  4. </form>

License

MIT