Skip to content

Commit beff827

Browse files
jrupacjamesdaily
authored andcommitted
feat(select): allow multiline ng-options
This patch allows the ng-options value of a <select> element to span multiple lines, which would previously throw an error when used with filters. Closes angular#5602
1 parent dd1bf57 commit beff827

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/ng/directive/select.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ var ngOptionsDirective = valueFn({ terminal: true });
129129
// jshint maxlen: false
130130
var selectDirective = ['$compile', '$parse', function($compile, $parse) {
131131
//0000111110000000000022220000000000000000000000333300000000000000444444444444444000000000555555555555555000000066666666666666600000000000000007777000000000000000000088888
132-
var NG_OPTIONS_REGEXP = /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/,
132+
var NG_OPTIONS_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/,
133133
nullModelCtrl = {$setViewValue: noop};
134134
// jshint maxlen: 100
135135

test/ng/directive/selectSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,31 @@ describe('select', function() {
708708
expect(sortedHtml(options[0])).toEqual('<option value="regularProperty">visible</option>');
709709
});
710710

711+
it('should allow expressions over multiple lines', function() {
712+
scope.isNotFoo = function(item) {
713+
return item.name !== 'Foo';
714+
};
715+
716+
createSelect({
717+
'ng-options': 'key.id\n' +
718+
'for key in object\n' +
719+
'| filter:isNotFoo',
720+
'ng-model': 'selected'
721+
});
722+
723+
scope.$apply(function() {
724+
scope.object = [{'id': 1, 'name': 'Foo'},
725+
{'id': 2, 'name': 'Bar'},
726+
{'id': 3, 'name': 'Baz'}];
727+
scope.selected = scope.object[0];
728+
});
729+
730+
var options = element.find('option');
731+
expect(options.length).toEqual(3);
732+
expect(sortedHtml(options[1])).toEqual('<option value="0">2</option>');
733+
expect(sortedHtml(options[2])).toEqual('<option value="1">3</option>');
734+
});
735+
711736
describe('binding', function() {
712737

713738
it('should bind to scope value', function() {

0 commit comments

Comments
 (0)