Created
July 14, 2014 19:55
-
-
Save pomack/b9ea257f2d79c1055f36 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
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