Skip to content

Instantly share code, notes, and snippets.

@sanjeevsubedi
Last active March 7, 2023 15:19
Show Gist options
  • Save sanjeevsubedi/b4c79bfcd1859f600dba7b3984e5c5e1 to your computer and use it in GitHub Desktop.
Save sanjeevsubedi/b4c79bfcd1859f600dba7b3984e5c5e1 to your computer and use it in GitHub Desktop.
Angular method decorator to implement setTimeout
/**
* 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