Skip to content

Instantly share code, notes, and snippets.

@gabor-farkas
Created December 9, 2015 16:54
Show Gist options
  • Save gabor-farkas/889c631da0ae99de2719 to your computer and use it in GitHub Desktop.
Save gabor-farkas/889c631da0ae99de2719 to your computer and use it in GitHub Desktop.
blog/ngmodel/bindExpression
.directive("bindExpression", function($parse) {
var directive = {};
directive.restrict = 'E';
directive.require = 'ngModel';
directive.link = function(scope, element, attrs, ngModel) {
scope.$watch(attrs.expression, function (newValue) {
ngModel.$setViewValue(newValue);
});
ngModel.$render = function() {
$parse(attrs.expression).assign(ngModel.viewValue);
}
};
return directive;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment