Skip to content

Instantly share code, notes, and snippets.

@tomeustace
Created November 12, 2019 15:40
Show Gist options
  • Save tomeustace/334c9777b9e26617eff464b8ef64997e to your computer and use it in GitHub Desktop.
Save tomeustace/334c9777b9e26617eff464b8ef64997e to your computer and use it in GitHub Desktop.
Angular decorator for overriding ngoninit, maybe extended to avoid multiple component instances
export function Singleton() {
return function(target, key, decorator) {
const method = decorator.value;
const myOverride = () => {
// do stuff
method.call();
}
decorator.value = myOverride;
return decorator;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment