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

fix(option): support option elements in datalist #1254

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ var optionDirective = ['$interpolate', function($interpolate) {
return {
restrict: 'E',
priority: 100,
require: '^select',
compile: function(element, attr) {
if (isUndefined(attr.value)) {
var interpolateFn = $interpolate(element.text(), true);
Expand All @@ -530,8 +529,13 @@ var optionDirective = ['$interpolate', function($interpolate) {
}
}

return function (scope, element, attr, selectCtrl) {
if (selectCtrl.databound) {
return function (scope, element, attr) {
var selectCtrlName = '$selectController',
parent = element.parent(),
selectCtrl = parent.data(selectCtrlName) ||
parent.parent().data(selectCtrlName); // in case we are in optgroup

if (selectCtrl && selectCtrl.databound) {
// For some reason Opera defaults to true and if not overridden this messes up the repeater.
// We don't want the view to drive the initialization of the model anyway.
element.prop('selected', false);
Expand Down
15 changes: 14 additions & 1 deletion test/ng/directive/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ describe('select', function() {
});


describe('OPTION value', function() {
describe('option', function() {

it('should populate value attribute on OPTION', function() {
compile('<select ng-model="x"><option selected>abc</option></select>');
Expand All @@ -1125,5 +1125,18 @@ describe('select', function() {
compile('<select ng-model="x"><option>hello</select>');
expect(element).toEqualSelect(['hello']);
});

it('should not blow up when option directive is found inside of a datalist',
inject(function($compile, $rootScope) {
var element = $compile('<div>' +
'<datalist><option>some val</option></datalist>' +
'<span>{{foo}}</span>' +
'</div>')($rootScope);

$rootScope.foo = 'success';
$rootScope.$digest();
expect(element.find('span').text()).toBe('success');
dealoc(element);
}));
});
});