@@ -1743,29 +1743,32 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
1743
1743
pendingDebounce = null ,
1744
1744
ctrl = this ;
1745
1745
1746
- var ngModelGet = function ngModelGet ( ) {
1747
- var modelValue = parsedNgModel ( $scope ) ;
1748
- if ( ctrl . $options && ctrl . $options . getterSetter && isFunction ( modelValue ) ) {
1749
- modelValue = modelValue ( ) ;
1750
- }
1751
- return modelValue ;
1752
- } ;
1753
-
1754
- var ngModelSet = function ngModelSet ( newValue ) {
1755
- var getterSetter ;
1756
- if ( ctrl . $options && ctrl . $options . getterSetter &&
1757
- isFunction ( getterSetter = parsedNgModel ( $scope ) ) ) {
1758
-
1759
- getterSetter ( ctrl . $modelValue ) ;
1760
- } else {
1761
- parsedNgModel . assign ( $scope , ctrl . $modelValue ) ;
1762
- }
1763
- } ;
1746
+ var ngModelGet = parsedNgModel ;
1747
+ var ngModelSet = ngModelGet . assign ;
1764
1748
1765
1749
this . $$setOptions = function ( options ) {
1766
1750
ctrl . $options = options ;
1767
1751
1768
- if ( ! parsedNgModel . assign && ( ! options || ! options . getterSetter ) ) {
1752
+ if ( options && options . getterSetter ) {
1753
+ var ngModelGetterGet = $parse ( $attr . ngModel + "()" ) ;
1754
+ var ngModelGetterSet = $parse ( $attr . ngModel + "($$ngModelValue)" ) ;
1755
+
1756
+ //TODO: remove support for the ngModel being a non-function when getterSetter is enabled
1757
+ ngModelGet = function ngModelGetterSetterGet ( $scope ) {
1758
+ var value = parsedNgModel ( $scope ) ;
1759
+ if ( isFunction ( value ) ) {
1760
+ value = ngModelGetterGet ( $scope ) ;
1761
+ }
1762
+ return value ;
1763
+ } ;
1764
+ ngModelSet = function ngModelGetterSetterSet ( $scope , value ) {
1765
+ if ( ! parsedNgModel . assign || isFunction ( parsedNgModel ( $scope ) ) ) {
1766
+ ngModelGetterSet ( $scope , { $$ngModelValue : value } ) ;
1767
+ } else {
1768
+ parsedNgModel . assign ( $scope , value ) ;
1769
+ }
1770
+ } ;
1771
+ } else if ( ! ngModelSet ) {
1769
1772
throw $ngModelMinErr ( 'nonassign' , "Expression '{0}' is non-assignable. Element: {1}" ,
1770
1773
$attr . ngModel , startingTag ( $element ) ) ;
1771
1774
}
@@ -2164,7 +2167,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
2164
2167
}
2165
2168
if ( isNumber ( ctrl . $modelValue ) && isNaN ( ctrl . $modelValue ) ) {
2166
2169
// ctrl.$modelValue has not been touched yet...
2167
- ctrl . $modelValue = ngModelGet ( ) ;
2170
+ ctrl . $modelValue = ngModelGet ( $scope ) ;
2168
2171
}
2169
2172
var prevModelValue = ctrl . $modelValue ;
2170
2173
var allowInvalid = ctrl . $options && ctrl . $options . allowInvalid ;
@@ -2192,7 +2195,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
2192
2195
} ;
2193
2196
2194
2197
this . $$writeModelToScope = function ( ) {
2195
- ngModelSet ( ctrl . $modelValue ) ;
2198
+ ngModelSet ( $scope , ctrl . $modelValue ) ;
2196
2199
forEach ( ctrl . $viewChangeListeners , function ( listener ) {
2197
2200
try {
2198
2201
listener ( ) ;
@@ -2288,7 +2291,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
2288
2291
// ng-change executes in apply phase
2289
2292
// 4. view should be changed back to 'a'
2290
2293
$scope . $watch ( function ngModelWatch ( ) {
2291
- var modelValue = ngModelGet ( ) ;
2294
+ var modelValue = ngModelGet ( $scope ) ;
2292
2295
2293
2296
// if scope model value and ngModel value are out of sync
2294
2297
// TODO(perf): why not move this to the action fn?
0 commit comments