@@ -394,15 +394,27 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
394394 validate ( ) ;
395395 $scope . refreshSelectedItems ( ) ;
396396
397- // Watch for changes in input model (allow dynamic input)
397+ // Watch for changes in input model
398+ // Updates multi-select when user select/deselect a single checkbox programatically
399+ // https://github.com/isteven/angular-multi-select/issues/8
398400 $scope . $watch ( 'inputModel' , function ( oldVal , newVal ) {
399- if ( $scope . inputModel !== 'undefined' ) {
401+ if ( $scope . newVal !== 'undefined' ) {
402+ validateProperties ( $scope . itemLabel . split ( ' ' ) , $scope . inputModel ) ;
403+ validateProperties ( new Array ( $scope . tickProperty ) , $scope . inputModel ) ;
404+ }
405+ $scope . refreshSelectedItems ( ) ;
406+ } , true ) ;
407+
408+ // Watch for changes in input model
409+ // This on updates the multi-select when a user load a whole new input-model. We also update the $scope.backUp variable
410+ $scope . $watch ( 'inputModel' , function ( oldVal , newVal ) {
411+ if ( $scope . newVal !== 'undefined' ) {
400412 validateProperties ( $scope . itemLabel . split ( ' ' ) , $scope . inputModel ) ;
401413 validateProperties ( new Array ( $scope . tickProperty ) , $scope . inputModel ) ;
402414 }
403415 $scope . backUp = angular . copy ( $scope . inputModel ) ;
404416 $scope . refreshSelectedItems ( ) ;
405- } ) ;
417+ } ) ;
406418
407419 // Watch for changes in directive state (disabled or enabled)
408420 $scope . $watch ( 'isDisabled' , function ( newVal ) {
0 commit comments