Last active
March 7, 2023 15:19
-
-
Save sanjeevsubedi/b4c79bfcd1859f600dba7b3984e5c5e1 to your computer and use it in GitHub Desktop.
Angular method decorator to implement setTimeout
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
/** | |
* Angular method decorator to implement setTimeout | |
* | |
*/ | |
export function timeout(milliseconds: number = 0) { | |
return function ( | |
prototype: any, | |
name: string, | |
descriptor: PropertyDescriptor | |
) { | |
const originalMethod = descriptor.value; | |
descriptor.value = function (...args: []) { | |
setTimeout(() => { | |
originalMethod.apply(this, args); | |
}, milliseconds); | |
}; | |
}; | |
} | |
/** | |
* How to use it? | |
* | |
* @timeout(1000) | |
* render() { | |
* ........... | |
* } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment