This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 3 files changed +27
-1
lines changed
3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 5
5
- Issue #449 : [ ng: options ] should support binding to a property of an item.
6
6
- Issue #464 : [ ng: options ] incorrectly re-grew options on datasource change
7
7
- Issue #448 : [ ng: options ] should support iterating over objects
8
+ - Issue #463 : [ ng: options ] should support firing ng: change event
8
9
9
10
### Breaking changes
10
11
- no longer support MMMMM in filter.date as we need to follow UNICODE LOCALE DATA formats.
Original file line number Diff line number Diff line change @@ -674,6 +674,7 @@ angularWidget('select', function(element){
674
674
this . directives ( true ) ;
675
675
var isMultiselect = element . attr ( 'multiple' ) ;
676
676
var expression = element . attr ( 'ng:options' ) ;
677
+ var onChange = expressionCompile ( element . attr ( 'ng:change' ) || "" ) . fnSelf ;
677
678
var match ;
678
679
if ( ! expression ) {
679
680
return inputWidgetSelector . call ( this , element ) ;
@@ -729,7 +730,10 @@ angularWidget('select', function(element){
729
730
value = valueFn ( tempScope ) ;
730
731
}
731
732
}
732
- if ( ! isUndefined ( value ) ) model . set ( value ) ;
733
+ if ( ! isUndefined ( value ) && model . get ( ) !== value ) {
734
+ onChange ( scope ) ;
735
+ model . set ( value ) ;
736
+ }
733
737
scope . $tryEval ( function ( ) {
734
738
scope . $root . $eval ( ) ;
735
739
} ) ;
Original file line number Diff line number Diff line change @@ -859,6 +859,27 @@ describe("widget", function(){
859
859
expect ( scope . selected ) . toEqual ( scope . values [ 1 ] ) ;
860
860
} ) ;
861
861
862
+ it ( 'should fire ng:change if present' , function ( ) {
863
+ createSelect ( {
864
+ name :'selected' ,
865
+ 'ng:options' :'value for value in values' ,
866
+ 'ng:change' :'count = count + 1' } ) ;
867
+ scope . values = [ { name :'A' } , { name :'B' } ] ;
868
+ scope . selected = scope . values [ 0 ] ;
869
+ scope . count = 0 ;
870
+ scope . $eval ( ) ;
871
+ expect ( scope . count ) . toEqual ( 0 ) ;
872
+
873
+ select . val ( '1' ) ;
874
+ browserTrigger ( select , 'change' ) ;
875
+ expect ( scope . count ) . toEqual ( 1 ) ;
876
+ expect ( scope . selected ) . toEqual ( scope . values [ 1 ] ) ;
877
+
878
+ browserTrigger ( select , 'change' ) ;
879
+ expect ( scope . count ) . toEqual ( 1 ) ;
880
+ expect ( scope . selected ) . toEqual ( scope . values [ 1 ] ) ;
881
+ } ) ;
882
+
862
883
it ( 'should update model on change through expression' , function ( ) {
863
884
createSelect ( { name :'selected' , 'ng:options' :'item.id as item.name for item in values' } ) ;
864
885
scope . values = [ { id :10 , name :'A' } , { id :20 , name :'B' } ] ;
You can’t perform that action at this time.
0 commit comments