Created
January 15, 2019 19:19
-
-
Save miladvafaeifard/3b9c95104aaae480e42a84bb793b6e1d to your computer and use it in GitHub Desktop.
Angular make @input on directive required
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
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