Skip to content

Instantly share code, notes, and snippets.

@miladvafaeifard
Created January 15, 2019 19:19
Show Gist options
  • Save miladvafaeifard/3b9c95104aaae480e42a84bb793b6e1d to your computer and use it in GitHub Desktop.
Save miladvafaeifard/3b9c95104aaae480e42a84bb793b6e1d to your computer and use it in GitHub Desktop.
Angular make @input on directive required
export function Required(target: object, propertyKey: string) {
console.log('required ....');
Object.defineProperty(target, propertyKey, {
get () {
throw new Error(`Attribute ${propertyKey} is required`);
},
set (value) {
Object.defineProperty(target, propertyKey, { value, writable: true, configurable: true });
},
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment