Skip to content

Instantly share code, notes, and snippets.

@EliCDavis
Created July 23, 2017 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EliCDavis/efc0f9e84d45bae0081555ef11daf6a6 to your computer and use it in GitHub Desktop.
Save EliCDavis/efc0f9e84d45bae0081555ef11daf6a6 to your computer and use it in GitHub Desktop.
import { Observable } from 'rxjs/Rx';
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ConditionallyValidateService } from 'ng-conditionally-validate';
@Component({
selector: 'app-example-two',
templateUrl: './example-two.component.html',
styleUrls: ['./example-two.component.css']
})
export class ExampleTwoComponent {
evilVisible$: Observable<boolean>;
form: FormGroup;
constructor(private cv: ConditionallyValidateService, private fb: FormBuilder) {
this.form = fb.group({
likesPinable: [false],
buyFromStarbucks: [false],
PAndM: [false],
boneless: [false],
reasonEvil: ['']
});
const evilValidate = cv.validate(this.form, 'reasonEvil').using(Validators.required);
this.evilVisible$ = evilValidate.when('likesPinable').is(true)
.combineLatest(
evilValidate.when('buyFromStarbucks').is(true),
evilValidate.when('PAndM').is(true),
evilValidate.when('boneless').is(true),
(pine, coffee, pm, boneless) => {
return pine || coffee || pm || boneless;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment