Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Created December 28, 2017 16:48
Show Gist options
  • Save brachi-wernick/1c47fb8bff98e2df5929cca425d94211 to your computer and use it in GitHub Desktop.
Save brachi-wernick/1c47fb8bff98e2df5929cca425d94211 to your computer and use it in GitHub Desktop.
@Directive({
selector: '[requiredIf]',
providers: [
{provide: NG_VALIDATORS,useExisting:RequiredIfDirective, multi: true}
]
})
export class RequiredIfDirective implements Validator {
@Input("requiredIf")
requiredIf: boolean;
validate(c:AbstractControl) {
let value = c.value;
if ((value == null || value == undefined || value == "") && this.requiredIf) {
return {
requiredIf: {condition:this.requiredIf}
};
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment