mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
fix(option): support option elements in datalist
previously we expected to find option elements only within select element and if that was not the case we throw an error. This made it impossible to include datalist element with nested option elements in the template. Closes #1165
This commit is contained in:
parent
167aa0c29c
commit
9767f7bdd3
2 changed files with 21 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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>');
|
||||
|
|
@ -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);
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue