Created
July 23, 2017 18:24
-
-
Save EliCDavis/efc0f9e84d45bae0081555ef11daf6a6 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 { 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