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

Commit cbb3ce2

Browse files
rhysbrettbowenIgorMinar
authored andcommitted
fix(ngRepeat): allow multiline expressions
allow and pass through new line characters when checking passed in expression Closes #5000
1 parent 45af02d commit cbb3ce2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ng/directive/ngRepeat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
203203
$$tlb: true,
204204
link: function($scope, $element, $attr, ctrl, $transclude){
205205
var expression = $attr.ngRepeat;
206-
var match = expression.match(/^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s+(.+)\s*)?$/),
206+
var match = expression.match(/^\s*(.+)\s+in\s+([\r\n\s\S]*?)\s*(\s+track\s+by\s+(.+)\s*)?$/),
207207
trackByExp, trackByExpGetter, trackByIdExpFn, trackByIdArrayFn, trackByIdObjFn,
208208
lhs, rhs, valueIdentifier, keyIdentifier,
209209
hashFnLocals = {$id: hashKey};

test/ng/directive/ngRepeatSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,22 @@ describe('ngRepeat', function() {
177177
});
178178

179179

180+
it('should allow expressions over multiple lines', function() {
181+
scope.isTrue = function() {
182+
return true;
183+
};
184+
element = $compile(
185+
'<ul>' +
186+
'<li ng-repeat="item in items\n' +
187+
'| filter:isTrue">{{item.name}}</li>' +
188+
'</ul>')(scope);
189+
scope.items = [{name: 'igor'}];
190+
scope.$digest();
191+
192+
expect(element.find('li').text()).toBe('igor');
193+
});
194+
195+
180196
it('should track using provided function when a filter is present', function() {
181197
scope.newArray = function (items) {
182198
var newArray = [];

0 commit comments

Comments
 (0)