mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-13 08:59:54 +08:00
@@ -5,6 +5,7 @@
|
||||
- Issue #449: [ng:options] should support binding to a property of an item.
|
||||
- Issue #464: [ng:options] incorrectly re-grew options on datasource change
|
||||
- Issue #448: [ng:options] should support iterating over objects
|
||||
- Issue #463: [ng:options] should support firing ng:change event
|
||||
|
||||
### Breaking changes
|
||||
- no longer support MMMMM in filter.date as we need to follow UNICODE LOCALE DATA formats.
|
||||
|
||||
@@ -674,6 +674,7 @@ angularWidget('select', function(element){
|
||||
this.directives(true);
|
||||
var isMultiselect = element.attr('multiple');
|
||||
var expression = element.attr('ng:options');
|
||||
var onChange = expressionCompile(element.attr('ng:change') || "").fnSelf;
|
||||
var match;
|
||||
if (!expression) {
|
||||
return inputWidgetSelector.call(this, element);
|
||||
@@ -729,7 +730,10 @@ angularWidget('select', function(element){
|
||||
value = valueFn(tempScope);
|
||||
}
|
||||
}
|
||||
if (!isUndefined(value)) model.set(value);
|
||||
if (!isUndefined(value) && model.get() !== value) {
|
||||
onChange(scope);
|
||||
model.set(value);
|
||||
}
|
||||
scope.$tryEval(function(){
|
||||
scope.$root.$eval();
|
||||
});
|
||||
|
||||
@@ -859,6 +859,27 @@ describe("widget", function(){
|
||||
expect(scope.selected).toEqual(scope.values[1]);
|
||||
});
|
||||
|
||||
it('should fire ng:change if present', function(){
|
||||
createSelect({
|
||||
name:'selected',
|
||||
'ng:options':'value for value in values',
|
||||
'ng:change':'count = count + 1'});
|
||||
scope.values = [{name:'A'}, {name:'B'}];
|
||||
scope.selected = scope.values[0];
|
||||
scope.count = 0;
|
||||
scope.$eval();
|
||||
expect(scope.count).toEqual(0);
|
||||
|
||||
select.val('1');
|
||||
browserTrigger(select, 'change');
|
||||
expect(scope.count).toEqual(1);
|
||||
expect(scope.selected).toEqual(scope.values[1]);
|
||||
|
||||
browserTrigger(select, 'change');
|
||||
expect(scope.count).toEqual(1);
|
||||
expect(scope.selected).toEqual(scope.values[1]);
|
||||
});
|
||||
|
||||
it('should update model on change through expression', function(){
|
||||
createSelect({name:'selected', 'ng:options':'item.id as item.name for item in values'});
|
||||
scope.values = [{id:10, name:'A'}, {id:20, name:'B'}];
|
||||
|
||||
Reference in New Issue
Block a user