Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit df73233

Browse files
committed
fix($compile): ignore optional =-bound properties with empty value
Previously, optional empty '='-bound expressions were ignored --- erroneously they stopped being ignored, and no tests were caused to fail for this reason. This change restores the original ignoring behaviour while still preventing other errors fixed by 8a1eb16 Closes #12144 Closes #12259
1 parent 69f1ebd commit df73233

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/ng/compile.js

+1
Original file line numberDiff line numberDiff line change
@@ -2591,6 +2591,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
25912591
if (optional) break;
25922592
attrs[attrName] = void 0;
25932593
}
2594+
if (optional && !attrs[attrName]) break;
25942595

25952596
parentGet = $parse(attrs[attrName]);
25962597
if (parentGet.literal) {

test/ng/compileSpec.js

+27
Original file line numberDiff line numberDiff line change
@@ -3618,6 +3618,33 @@ describe('$compile', function() {
36183618
});
36193619

36203620

3621+
it('should ignore optional "="-bound property if value is the emptry string', function() {
3622+
module(function($compileProvider) {
3623+
$compileProvider.directive('testDir', valueFn({
3624+
scope: {prop: '=?'},
3625+
controller: function($scope) {
3626+
$scope.prop = $scope.prop || 'default';
3627+
this.getProp = function() {
3628+
return $scope.prop;
3629+
};
3630+
},
3631+
controllerAs: 'ctrl',
3632+
template: '<p></p>'
3633+
}));
3634+
});
3635+
inject(function($compile, $rootScope) {
3636+
element = $compile('<div test-dir></div>')($rootScope);
3637+
var scope = element.isolateScope();
3638+
expect(scope.ctrl.getProp()).toBe('default');
3639+
$rootScope.$digest();
3640+
expect(scope.ctrl.getProp()).toBe('default');
3641+
scope.prop = 'foop';
3642+
$rootScope.$digest();
3643+
expect(scope.ctrl.getProp()).toBe('foop');
3644+
});
3645+
});
3646+
3647+
36213648
describe('bind-once', function() {
36223649

36233650
function countWatches(scope) {

0 commit comments

Comments
 (0)