Guest User

Untitled

a guest
Feb 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. export function Mandatory() {
  2. return function(target: any, propertyKey: string) {
  3. const ngOnInit = target.constructor.prototype.ngOnInit;
  4. target.constructor.prototype.ngOnInit = function(...args) {
  5. if (target[propertyKey] === null || target[propertyKey] === undefined) {
  6. throw Error(
  7. `mandatory property: ${propertyKey} not initialized. Current value is ${target[propertyKey]}`
  8. );
  9. }
  10. return ngOnInit && ngOnInit.apply(this, args);
  11. };
  12. };
  13. }
Add Comment
Please, Sign In to add comment