Skip to content

Instantly share code, notes, and snippets.

@EliCDavis
Last active July 23, 2017 18:26
Show Gist options
  • Save EliCDavis/241577d528e9948408ca02705b7b6dac to your computer and use it in GitHub Desktop.
Save EliCDavis/241577d528e9948408ca02705b7b6dac to your computer and use it in GitHub Desktop.
Examples For ng-conditionally-validate
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