File tree 2 files changed +33
-2
lines changed
2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -3836,8 +3836,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3836
3836
return {
3837
3837
pre : function ngPropPreLinkFn ( scope , $element ) {
3838
3838
function applyPropValue ( ) {
3839
- var propValue = ngPropGetter ( scope ) ;
3840
- $element . prop ( propName , sanitizer ( propValue ) ) ;
3839
+ var propValue = sanitizer ( ngPropGetter ( scope ) ) ;
3840
+
3841
+ if ( propValue !== undefined ) {
3842
+ $element . prop ( propName , propValue ) ;
3843
+ } else {
3844
+ $element . removeProp ( propName ) ;
3845
+ }
3841
3846
}
3842
3847
3843
3848
applyPropValue ( ) ;
Original file line number Diff line number Diff line change @@ -49,6 +49,32 @@ describe('ngProp*', function() {
49
49
expect ( element . prop ( 'asdf' ) ) . toBe ( true ) ;
50
50
} ) ) ;
51
51
52
+ // https://github.com/angular/angular.js/issues/16797
53
+ it ( 'should support falsy property values' , inject ( function ( $rootScope , $compile ) {
54
+ var element = $compile ( '<span ng-prop-text="myText" />' ) ( $rootScope ) ;
55
+ // Initialze to non-falsey
56
+ $rootScope . myText = 'abc' ;
57
+ $rootScope . $digest ( ) ;
58
+ expect ( element . prop ( 'text' ) ) . toBe ( 'abc' ) ;
59
+
60
+ // Assert various falsey values get assigned to the property
61
+ $rootScope . myText = '' ;
62
+ $rootScope . $digest ( ) ;
63
+ expect ( element . prop ( 'text' ) ) . toBe ( '' ) ;
64
+ $rootScope . myText = 0 ;
65
+ $rootScope . $digest ( ) ;
66
+ expect ( element . prop ( 'text' ) ) . toBe ( 0 ) ;
67
+ $rootScope . myText = false ;
68
+ $rootScope . $digest ( ) ;
69
+ expect ( element . prop ( 'text' ) ) . toBe ( false ) ;
70
+ $rootScope . myText = undefined ;
71
+ $rootScope . $digest ( ) ;
72
+ expect ( element . prop ( 'text' ) ) . toBeUndefined ( ) ;
73
+ $rootScope . myText = null ;
74
+ $rootScope . $digest ( ) ;
75
+ expect ( element . prop ( 'text' ) ) . toBe ( null ) ;
76
+ } ) ) ;
77
+
52
78
it ( 'should support mixed case using underscore-separated names' , inject ( function ( $rootScope , $compile ) {
53
79
var element = $compile ( '<span ng-prop-a_bcd_e="value" />' ) ( $rootScope ) ;
54
80
$rootScope . value = 123 ;
You can’t perform that action at this time.
0 commit comments