Skip to content

Commit

Permalink
fix(collectionRepeat): with ngHref, make href attr erase if falsy
Browse files Browse the repository at this point in the history
Fixes #1674
  • Loading branch information
ajoslin committed Aug 11, 2014
1 parent 5e025fb commit 977f681
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions js/angular/directive/collectionRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ var COLLECTION_REPEAT_ATTR_WIDTH_ERROR = "collection-repeat expected attribute c
var COLLECTION_REPEAT_ATTR_REPEAT_ERROR = "collection-repeat expected expression in form of '_item_ in _collection_[ track by _id_]' but got '%'";

IonicModule
.directive({
ngSrc: collectionRepeatSrcDirective('ngSrc', 'src'),
ngSrcset: collectionRepeatSrcDirective('ngSrcset', 'srcset'),
ngHref: collectionRepeatSrcDirective('ngHref', 'href')
})
.directive('collectionRepeat', [
'$collectionRepeatManager',
'$collectionDataSource',
Expand Down Expand Up @@ -263,7 +258,12 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
});
}
};
}]);
}])
.directive({
ngSrc: collectionRepeatSrcDirective('ngSrc', 'src'),
ngSrcset: collectionRepeatSrcDirective('ngSrcset', 'srcset'),
ngHref: collectionRepeatSrcDirective('ngHref', 'href')
});

// Fix for #1674
// Problem: if an ngSrc or ngHref expression evaluates to a falsy value, it will
Expand All @@ -277,13 +277,11 @@ function collectionRepeatSrcDirective(ngAttrName, attrName) {
return [function() {
return {
priority: '99', // it needs to run after the attributes are interpolated
link: function(scope, element, attr, collectionRepeatCtrl) {
if (!collectionRepeatCtrl) return;
link: function(scope, element, attr) {
attr.$observe(ngAttrName, function(value) {
element[0][attr] = '';
setTimeout(function() {
element[0][attr] = value;
});
if (!value) {
element[0].removeAttribute(attrName);
}
});
}
};
Expand Down

0 comments on commit 977f681

Please sign in to comment.