Last active
July 12, 2017 15:38
-
-
Save jinhduong/53dc823525ded39b72c246faf988ecfb to your computer and use it in GitHub Desktop.
Loading-indicator Decorators in Angular 2/4
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 LoadingIndicator(): MethodDecorator { | |
return function (target: Object, propertyKey: string | symbol, descriptor) { | |
const originalMethod = descriptor.value; | |
descriptor.value = function (...args) { | |
// Inject your show loading function HERE | |
const subs = originalMethod.apply(this, args); | |
// If it's using do operator | |
if (subs.subscribe) { | |
subs.subscribe(() => { | |
// Stop your show loading function HERE | |
}); | |
} else { | |
// If it's using subscribe | |
const _interval = setInterval(() => { | |
if (subs.isStopped) { | |
// Or stop your show loading function HERE | |
clearInterval(_interval); | |
} | |
}, 50); | |
}; | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment