mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-22 13:21:51 +00:00
parent
15183f3e1f
commit
26adeb119b
2 changed files with 23 additions and 2 deletions
|
|
@ -265,7 +265,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
|
||||||
var lastView;
|
var lastView;
|
||||||
ctrl.$render = function() {
|
ctrl.$render = function() {
|
||||||
var items = new HashMap(ctrl.$viewValue);
|
var items = new HashMap(ctrl.$viewValue);
|
||||||
forEach(selectElement.children(), function(option) {
|
forEach(selectElement.find('option'), function(option) {
|
||||||
option.selected = isDefined(items.get(option.value));
|
option.selected = isDefined(items.get(option.value));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -282,7 +282,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
|
||||||
selectElement.bind('change', function() {
|
selectElement.bind('change', function() {
|
||||||
scope.$apply(function() {
|
scope.$apply(function() {
|
||||||
var array = [];
|
var array = [];
|
||||||
forEach(selectElement.children(), function(option) {
|
forEach(selectElement.find('option'), function(option) {
|
||||||
if (option.selected) {
|
if (option.selected) {
|
||||||
array.push(option.value);
|
array.push(option.value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -405,6 +405,27 @@ describe('select', function() {
|
||||||
expect(element).toEqualSelect(['A'], ['B']);
|
expect(element).toEqualSelect(['A'], ['B']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should work with optgroups', function() {
|
||||||
|
compile('<select ng-model="selection" multiple>' +
|
||||||
|
'<optgroup label="group1">' +
|
||||||
|
'<option>A</option>' +
|
||||||
|
'<option>B</option>' +
|
||||||
|
'</optgroup>' +
|
||||||
|
'</select>');
|
||||||
|
|
||||||
|
expect(element).toEqualSelect('A', 'B');
|
||||||
|
expect(scope.selection).toBeUndefined();
|
||||||
|
|
||||||
|
scope.$apply(function() {
|
||||||
|
scope.selection = ['A'];
|
||||||
|
});
|
||||||
|
expect(element).toEqualSelect(['A'], 'B');
|
||||||
|
|
||||||
|
scope.$apply(function() {
|
||||||
|
scope.selection.push('B');
|
||||||
|
});
|
||||||
|
expect(element).toEqualSelect(['A'], ['B']);
|
||||||
|
});
|
||||||
|
|
||||||
it('should require', function() {
|
it('should require', function() {
|
||||||
compile(
|
compile(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue