Skip to content

Instantly share code, notes, and snippets.

@worldspawn
Last active August 29, 2015 14:16
Show Gist options
  • Save worldspawn/a274f61eb3202523f6a1 to your computer and use it in GitHub Desktop.
Save worldspawn/a274f61eb3202523f6a1 to your computer and use it in GitHub Desktop.
Two Way Binder - For use in non-isolated scope scenarios
.factory('twoWayBinder', function ($parse) {
function twoWayBind($scope, remote, local){
var remoteSetter = $parse(remote).assign;
var localSetter = $parse(local).assign;
$scope.$watch(remote, function (value) {
localSetter($scope, value);
});
$scope.$watch(local, function (value) {
remoteSetter($scope, value);
});
}
return {
bind : twoWayBind
};
});
@worldspawn
Copy link
Author

Code doesn't need to look at the parent scope. The expression should resolve on an inherited or shared scope. If the scope is isolated you shouldn't be using this script - use the scope : { ... } syntax provided by directives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment