Skip to content

Instantly share code, notes, and snippets.

@pomack
Created July 14, 2014 19:55
Show Gist options
  • Save pomack/b9ea257f2d79c1055f36 to your computer and use it in GitHub Desktop.
Save pomack/b9ea257f2d79c1055f36 to your computer and use it in GitHub Desktop.
function ngBindOutToAttribute(element, attributes, attribName, scope, scopeSource, initialize) {
var elementScope = element.scope(),
attribField = attributes[attribName],
valGetter = $parse(attributes[attribName]),
valSetter = valGetter.assign,
scopeGetter = $parse(scopeSource),
scopeSetter = scopeGetter.assign;
if(angular.isUndefined(scopeGetter(scope) && (angular.isUndefined(initialize) || initialize === true))) {
scopeSetter(scope, valGetter(elementScope));
}
scope.$watch(scopeSource, function() {
var useScope = elementScope;
if(attribField.indexOf('.') < 0 && attribField.indexOf('[') < 0) {
if(angular.isDefined(valGetter(useScope))) {
while(angular.isUndefined(useScope[attribField])) {
if(useScope.__proto__ === useScope.$parent) {
useScope = useScope.$parent;
} else {
break;
}
}
}
}
valSetter(useScope, scopeGetter(scope));
ngApply(elementScope);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment