Last active
July 23, 2017 18:26
-
-
Save EliCDavis/241577d528e9948408ca02705b7b6dac to your computer and use it in GitHub Desktop.
Examples For ng-conditionally-validate
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 { Component } from '@angular/core'; | |
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | |
import { ConditionallyValidateService } from 'ng-conditionally-validate'; | |
@Component({ | |
selector: 'app-example-one', | |
templateUrl: './example-one.component.html', | |
styleUrls: ['./example-one.component.css'] | |
}) | |
export class ExampleOneComponent { | |
form: FormGroup; | |
constructor(private cv: ConditionallyValidateService, private fb: FormBuilder) { | |
this.form = fb.group({ | |
human: [false], | |
food: [''], | |
drink: [''] | |
}); | |
cv.validate(this.form, 'food', 'drink') | |
.using(Validators.required) | |
.when('human') | |
.is(true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment