Created
March 17, 2020 16:25
-
-
Save fen89/0b886e22c19faa8751e01b0f559e546c to your computer and use it in GitHub Desktop.
Angular Invy print current selected component props (and observables) in browser console
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
current = ng.getComponent($0); | |
console.group(`${$0.localName} observables`); | |
observables = getObservables(current); | |
observables.forEach(({ key, value }) => value.subscribe(current => console.log(key, current))); | |
console.groupEnd(); | |
console.group(`${$0.localName} props`); | |
props = getNonObservables(current); | |
props.forEach(({ key, value }) => console.log(key, value)); | |
console.groupEnd(); | |
function isObservable(value) { | |
return (value.hasOwnProperty('_isScalar') && value['_isScalar'] === false); | |
} | |
function getObservables(component) { | |
const observables = Object.keys(component) | |
.map(key => ({ key: key, value: component[key]})) | |
.filter(property => isObservable(property.value)) | |
return observables; | |
} | |
function getNonObservables(component) { | |
const nonObservables = Object.keys(component) | |
.map(key => ({ key: key, value: component[key]})) | |
.filter(property => !isObservable(property.value)) | |
return nonObservables; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment