Skip to content

Instantly share code, notes, and snippets.

@zbarbuto
Last active May 28, 2018 01:35
Show Gist options
  • Save zbarbuto/0b16e05111d5a7e9ab09aad225c21281 to your computer and use it in GitHub Desktop.
Save zbarbuto/0b16e05111d5a7e9ab09aad225c21281 to your computer and use it in GitHub Desktop.
Developer function list
@Component({
template: `
<div *ngFor="let component of components">
<h4>{{ component.name }}</h4>
<button
*ngFor="let devFun of component.developerFunctions"
(click)="callMethod(component.componentInstance, devFun)">
{{ devFun.name }}
</button>
</div>
`,
selector: 'developer-function-list',
})
export class DeveloperFunctionList {
components = this.probeForComponents();
public callMethod(componentInstance: any, devFun: any) {
componentInstance[devFun.name]();
}
probeForComponents() {
const components = getComponents(); // Recurse through dom for components using ng.probe - ommitted for berevity
return components
.filter(comp => !!comp.componentInstance)
.map(component => {
const developerFunctions = Reflect.getMetadata(comp.componentInstance.constructor, 'DEVELOPER_FUNCTIONS`);
return {
component,
developerFunctions
};
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment