mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-13 08:59:54 +08:00
@@ -415,6 +415,18 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
|
||||
ctrl.$render = render;
|
||||
|
||||
scope.$watchCollection(valuesFn, scheduleRendering);
|
||||
scope.$watchCollection(function () {
|
||||
var locals = {},
|
||||
values = valuesFn(scope);
|
||||
if (values) {
|
||||
var toDisplay = new Array(values.length);
|
||||
for (var i = 0, ii = values.length; i < ii; i++) {
|
||||
locals[valueName] = values[i];
|
||||
toDisplay[i] = displayFn(scope, locals);
|
||||
}
|
||||
return toDisplay;
|
||||
}
|
||||
}, scheduleRendering);
|
||||
|
||||
if (multiple) {
|
||||
scope.$watchCollection(function() { return ctrl.$modelValue; }, scheduleRendering);
|
||||
|
||||
@@ -871,6 +871,26 @@ describe('select', function() {
|
||||
expect(element.val()).toEqual('1');
|
||||
});
|
||||
|
||||
it('should update options in the DOM', function() {
|
||||
compile(
|
||||
'<select ng-model="selected" ng-options="item.id as item.name for item in values"></select>'
|
||||
);
|
||||
|
||||
scope.$apply(function() {
|
||||
scope.values = [{id: 10, name: 'A'}, {id: 20, name: 'B'}];
|
||||
scope.selected = scope.values[0].id;
|
||||
});
|
||||
|
||||
scope.$apply(function() {
|
||||
scope.values[0].name = 'C';
|
||||
});
|
||||
|
||||
var options = element.find('option');
|
||||
expect(options.length).toEqual(2);
|
||||
expect(sortedHtml(options[0])).toEqual('<option value="0">C</option>');
|
||||
expect(sortedHtml(options[1])).toEqual('<option value="1">B</option>');
|
||||
});
|
||||
|
||||
|
||||
it('should bind to object key', function() {
|
||||
createSelect({
|
||||
|
||||
Reference in New Issue
Block a user