@@ -90,9 +90,7 @@ Use this directive to render a button with a dropdown of alternative actions.
9090**/
9191( function ( ) {
9292 'use strict' ;
93-
9493 function ButtonGroupDirective ( ) {
95-
9694 function controller ( $scope , localizationService ) {
9795 $scope . toggleStyle = null ;
9896 $scope . blockElement = false ;
@@ -125,26 +123,32 @@ Use this directive to render a button with a dropdown of alternative actions.
125123 // As the <localize /> directive doesn't support Angular expressions as fallback, we instead listen for changes
126124 // to the label key of the default button, and if detected, we update the button label with the localized value
127125 // received from the localization service
128- $scope . $watch ( "defaultButton.labelKey" , function ( ) {
129- if ( ! $scope . defaultButton . labelKey ) return ;
126+ $scope . $watch ( "defaultButton" , localizeDefaultButtonLabel ) ;
127+ $scope . $watch ( "defaultButton.labelKey" , localizeDefaultButtonLabel ) ;
128+
129+ function localizeDefaultButtonLabel ( ) {
130+ if ( ! $scope . defaultButton ?. labelKey ) return ;
130131 localizationService . localize ( $scope . defaultButton . labelKey ) . then ( value => {
131132 if ( value && value . indexOf ( "[" ) === 0 ) return ;
132133 $scope . defaultButton . label = value ;
133134 } ) ;
134- } ) ;
135+ }
135136
136137 // In a similar way, we must listen for changes to the sub buttons (or their label keys), and if detected, update
137138 // the label with the localized value received from the localization service
138- $scope . $watch ( "defaultButton.subButtons" , function ( ) {
139- if ( ! Array . isArray ( $scope . subButtons ) ) return ;
139+ $scope . $watch ( "subButtons" , localizeSubButtons , true ) ;
140+ $scope . $watch ( "defaultButton.subButtons" , localizeSubButtons , true ) ;
141+
142+ function localizeSubButtons ( ) {
143+ if ( ! $scope . subButtons || ! Array . isArray ( $scope . subButtons ) ) return ;
140144 $scope . subButtons . forEach ( function ( sub ) {
141145 if ( ! sub . labelKey ) return ;
142146 localizationService . localize ( sub . labelKey ) . then ( value => {
143147 if ( value && value . indexOf ( "[" ) === 0 ) return ;
144148 sub . label = value ;
145149 } ) ;
146150 } ) ;
147- } , true ) ;
151+ }
148152
149153 }
150154
0 commit comments