Skip to content

Commit 977f681

Browse files
committed
fix(collectionRepeat): with ngHref, make href attr erase if falsy
Fixes #1674
1 parent 5e025fb commit 977f681

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

Diff for: js/angular/directive/collectionRepeat.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,6 @@ var COLLECTION_REPEAT_ATTR_WIDTH_ERROR = "collection-repeat expected attribute c
133133
var COLLECTION_REPEAT_ATTR_REPEAT_ERROR = "collection-repeat expected expression in form of '_item_ in _collection_[ track by _id_]' but got '%'";
134134

135135
IonicModule
136-
.directive({
137-
ngSrc: collectionRepeatSrcDirective('ngSrc', 'src'),
138-
ngSrcset: collectionRepeatSrcDirective('ngSrcset', 'srcset'),
139-
ngHref: collectionRepeatSrcDirective('ngHref', 'href')
140-
})
141136
.directive('collectionRepeat', [
142137
'$collectionRepeatManager',
143138
'$collectionDataSource',
@@ -263,7 +258,12 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
263258
});
264259
}
265260
};
266-
}]);
261+
}])
262+
.directive({
263+
ngSrc: collectionRepeatSrcDirective('ngSrc', 'src'),
264+
ngSrcset: collectionRepeatSrcDirective('ngSrcset', 'srcset'),
265+
ngHref: collectionRepeatSrcDirective('ngHref', 'href')
266+
});
267267

268268
// Fix for #1674
269269
// Problem: if an ngSrc or ngHref expression evaluates to a falsy value, it will
@@ -277,13 +277,11 @@ function collectionRepeatSrcDirective(ngAttrName, attrName) {
277277
return [function() {
278278
return {
279279
priority: '99', // it needs to run after the attributes are interpolated
280-
link: function(scope, element, attr, collectionRepeatCtrl) {
281-
if (!collectionRepeatCtrl) return;
280+
link: function(scope, element, attr) {
282281
attr.$observe(ngAttrName, function(value) {
283-
element[0][attr] = '';
284-
setTimeout(function() {
285-
element[0][attr] = value;
286-
});
282+
if (!value) {
283+
element[0].removeAttribute(attrName);
284+
}
287285
});
288286
}
289287
};

0 commit comments

Comments
 (0)