diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index ab642338358e..558cce14fe7a 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1855,7 +1855,15 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ }; this.$$writeModelToScope = function() { - ngModelSet($scope, ctrl.$modelValue); + var getterSetter; + + if (ctrl.$options && ctrl.$options.getterSetter && + isFunction(getterSetter = ngModelGet($scope))) { + + getterSetter(ctrl.$modelValue); + } else { + ngModelSet($scope, ctrl.$modelValue); + } forEach(ctrl.$viewChangeListeners, function(listener) { try { listener(); @@ -1930,6 +1938,10 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ $scope.$watch(function ngModelWatch() { var modelValue = ngModelGet($scope); + if (ctrl.$options && ctrl.$options.getterSetter && isFunction(modelValue)) { + modelValue = modelValue(); + } + // if scope model value and ngModel value are out of sync if (ctrl.$modelValue !== modelValue && (isUndefined(ctrl.$$invalidModelValue) || ctrl.$$invalidModelValue != modelValue)) { @@ -2062,6 +2074,55 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ * + * + * ## Binding to a getter/setter + * + * Sometimes it's helpful to bind `ngModel` to a getter/setter function. A getter/setter is a + * function that returns a representation of the model when called with zero arguments, and sets + * the internal state of a model when called with an argument. It's sometimes useful to use this + * for models that have an internal representation that's different than what the model exposes + * to the view. + * + *