This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -1756,12 +1756,15 @@ var ngValueDirective = function() {
1756
1756
compile : function ( tpl , tplAttr ) {
1757
1757
if ( CONSTANT_VALUE_REGEXP . test ( tplAttr . ngValue ) ) {
1758
1758
return function ngValueConstantLink ( scope , elm , attr ) {
1759
- attr . $set ( 'value' , scope . $eval ( attr . ngValue ) ) ;
1759
+ var value = scope . $eval ( attr . ngValue ) ;
1760
+ attr . $set ( 'value' , value ) ;
1761
+ elm [ 0 ] . value = value ;
1760
1762
} ;
1761
1763
} else {
1762
1764
return function ngValueLink ( scope , elm , attr ) {
1763
1765
scope . $watch ( attr . ngValue , function valueWatchAction ( value ) {
1764
1766
attr . $set ( 'value' , value ) ;
1767
+ elm [ 0 ] . value = value ;
1765
1768
} ) ;
1766
1769
} ;
1767
1770
}
Original file line number Diff line number Diff line change @@ -3046,7 +3046,26 @@ describe('input', function() {
3046
3046
expect ( inputElm [ 0 ] . getAttribute ( 'value' ) ) . toBe ( 'something' ) ;
3047
3047
} ) ;
3048
3048
3049
+ it ( 'should update the input "value" property and attribute after change the "value" property' , function ( ) {
3050
+ var inputElm = helper . compileInput ( '<input type="text" ng-value="value">' ) ;
3049
3051
3052
+ $rootScope . $apply ( function ( ) {
3053
+ $rootScope . value = 'something' ;
3054
+ } ) ;
3055
+ expect ( inputElm [ 0 ] . value ) . toBe ( 'something' ) ;
3056
+ expect ( inputElm [ 0 ] . getAttribute ( 'value' ) ) . toBe ( 'something' ) ;
3057
+
3058
+ helper . changeInputValueTo ( 'newValue' ) ;
3059
+
3060
+ $rootScope . $apply ( function ( ) {
3061
+ $rootScope . value = 'anotherValue' ;
3062
+ } ) ;
3063
+ expect ( inputElm [ 0 ] . value ) . toBe ( 'anotherValue' ) ;
3064
+ expect ( inputElm [ 0 ] . getAttribute ( 'value' ) ) . toBe ( 'anotherValue' ) ;
3065
+
3066
+
3067
+ } ) ;
3068
+
3050
3069
it ( 'should evaluate and set constant expressions' , function ( ) {
3051
3070
var inputElm = helper . compileInput ( '<input type="radio" ng-model="selected" ng-value="true">' +
3052
3071
'<input type="radio" ng-model="selected" ng-value="false">' +
You can’t perform that action at this time.
0 commit comments