Created
July 23, 2017 18:25
-
-
Save EliCDavis/aa3cf02124ae36ed47649428de854f98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | |
import { Component, OnInit } from '@angular/core'; | |
import { ConditionallyValidateService } from 'ng-conditionally-validate'; | |
@Component({ | |
selector: 'app-example-three', | |
templateUrl: './example-three.component.html', | |
styleUrls: ['./example-three.component.css'] | |
}) | |
export class ExampleThreeComponent { | |
form: FormGroup; | |
constructor( | |
private fb: FormBuilder, | |
private cv: ConditionallyValidateService | |
) { | |
this.form = fb.group({ | |
typeOfAccount: ['normal'], | |
password: ['', [Validators.minLength(6), Validators.required]] | |
}); | |
const passwordRule = cv.validate(this.form, 'password'); | |
passwordRule.using(Validators.minLength(12)) | |
.when('typeOfAccount') | |
.is('admin'); | |
passwordRule.using(Validators.minLength(18)) | |
.when('typeOfAccount') | |
.is('super'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment