This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree 2 files changed +21
-4
lines changed
2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -14,11 +14,9 @@ angular.module('ui.bootstrap.buttons', [])
14
14
require :'ngModel' ,
15
15
link :function ( scope , element , attrs , ngModelCtrl ) {
16
16
17
- var value = scope . $eval ( attrs . btnRadio ) ;
18
-
19
17
//model -> UI
20
18
ngModelCtrl . $render = function ( ) {
21
- if ( angular . equals ( ngModelCtrl . $modelValue , value ) ) {
19
+ if ( angular . equals ( ngModelCtrl . $modelValue , scope . $eval ( attrs . btnRadio ) ) ) {
22
20
element . addClass ( activeClass ) ;
23
21
} else {
24
22
element . removeClass ( activeClass ) ;
@@ -29,7 +27,7 @@ angular.module('ui.bootstrap.buttons', [])
29
27
element . bind ( toggleEvent , function ( ) {
30
28
if ( ! element . hasClass ( activeClass ) ) {
31
29
scope . $apply ( function ( ) {
32
- ngModelCtrl . $setViewValue ( value ) ;
30
+ ngModelCtrl . $setViewValue ( scope . $eval ( attrs . btnRadio ) ) ;
33
31
ngModelCtrl . $render ( ) ;
34
32
} ) ;
35
33
}
Original file line number Diff line number Diff line change @@ -100,5 +100,24 @@ describe('buttons', function () {
100
100
expect ( btns . eq ( 1 ) ) . toHaveClass ( 'active' ) ;
101
101
expect ( btns . eq ( 0 ) ) . not . toHaveClass ( 'active' ) ;
102
102
} ) ;
103
+
104
+ it ( 'should watch btn-radio values and update state accordingly' , function ( ) {
105
+ $scope . values = [ "value1" , "value2" ] ;
106
+
107
+ var btns = compileButtons ( '<button ng-model="model" btn-radio="values[0]">click1</button><button ng-model="model" btn-radio="values[1]">click2</button>' , $scope ) ;
108
+ expect ( btns . eq ( 0 ) ) . not . toHaveClass ( 'active' ) ;
109
+ expect ( btns . eq ( 1 ) ) . not . toHaveClass ( 'active' ) ;
110
+
111
+ $scope . model = "value2" ;
112
+ $scope . $digest ( ) ;
113
+ expect ( btns . eq ( 0 ) ) . not . toHaveClass ( 'active' ) ;
114
+ expect ( btns . eq ( 1 ) ) . toHaveClass ( 'active' ) ;
115
+
116
+ $scope . values [ 1 ] = "value3" ;
117
+ $scope . model = "value3" ;
118
+ $scope . $digest ( ) ;
119
+ expect ( btns . eq ( 0 ) ) . not . toHaveClass ( 'active' ) ;
120
+ expect ( btns . eq ( 1 ) ) . toHaveClass ( 'active' ) ;
121
+ } ) ;
103
122
} ) ;
104
123
} ) ;
You can’t perform that action at this time.
0 commit comments