fix(ngRepeat): allow multiline expressions

allow and pass through new line characters when checking passed in expression

Closes #5000
This commit is contained in:
Rhys Brett-bowen 2013-11-18 10:02:55 -05:00 committed by Igor Minar
parent 45af02de04
commit cbb3ce2c30
2 changed files with 17 additions and 1 deletions

View file

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

View file

@ -177,6 +177,22 @@ describe('ngRepeat', function() {
});
it('should allow expressions over multiple lines', function() {
scope.isTrue = function() {
return true;
};
element = $compile(
'<ul>' +
'<li ng-repeat="item in items\n' +
'| filter:isTrue">{{item.name}}</li>' +
'</ul>')(scope);
scope.items = [{name: 'igor'}];
scope.$digest();
expect(element.find('li').text()).toBe('igor');
});
it('should track using provided function when a filter is present', function() {
scope.newArray = function (items) {
var newArray = [];