Created
December 28, 2017 16:48
-
-
Save brachi-wernick/1c47fb8bff98e2df5929cca425d94211 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@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