Skip to content

Instantly share code, notes, and snippets.

@DarkArc
Last active September 16, 2016 19:37
Show Gist options
  • Save DarkArc/e7c9700588afa6b146f50107a941021a to your computer and use it in GitHub Desktop.
Save DarkArc/e7c9700588afa6b146f50107a941021a to your computer and use it in GitHub Desktop.
Search up through an angular scope to find the object holding a given named scope variable
function findKey(searchObject, scopeVariableName) {
for (var objectKey in searchObject) {
if (objectKey === scopeVariableName) {
return searchObject;
} else if (objectKey === '$parent' && searchObject[objectKey] instanceof Object) {
if (searchObject.hasOwnProperty(objectKey)) {
var result = findKey(searchObject[objectKey], scopeVariableName);
if (result) {
return result;
}
}
}
}
return null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment