Skip to content

Instantly share code, notes, and snippets.

@hdeshev
Created February 2, 2016 15:24
Show Gist options
  • Save hdeshev/56beacc042750b755846 to your computer and use it in GitHub Desktop.
Save hdeshev/56beacc042750b755846 to your computer and use it in GitHub Desktop.
import {Directive, ElementRef, Input} from "angular2/core";
import {View} from "ui/core/view";
@Directive({
selector: '[dump]'
})
export class DumpDirective {
@Input('dump') name: any;
constructor(private element: ElementRef) {
}
public ngOnInit() {
setTimeout(() => this.dumpView(this.element.nativeElement), 100);
}
public dumpView(view: View, level:number = 0) {
const prefix = (new Array(level + 1)).join("--");
if (level === 0) {
console.log('DUMPING VISUAL TREE: ' + this.name);
}
const text = (<any>view).nodeName || view.toString();
const id = (<any>view).text || ''
console.log(`${prefix}${text}: ${id.substr(0, 20)}`);
(<any>view)._eachChildView((child) => {
this.dumpView(child, level + 1);
return true;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment