Created
February 2, 2016 15:24
-
-
Save hdeshev/56beacc042750b755846 to your computer and use it in GitHub Desktop.
This file contains 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
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