Last active
August 29, 2015 14:16
-
-
Save worldspawn/a274f61eb3202523f6a1 to your computer and use it in GitHub Desktop.
Two Way Binder - For use in non-isolated scope scenarios
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
.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 | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.