Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs concatenate string with multi-checkbox

I'm trying to refresh and concatenate a string when multiple checkboxes is checked.

For example, when 'apple' and 'banana' are checked, $scope.string should be ='ab', then when 'banana' is unchecked, $scope.string should be left with 'a'.

What I did does concatenate, however $scope.string won't remove old values, it is still ='aba'

Here is my attempt on JsFiddle.

You can see when all checkboxes are checked it gives me aababcabcd

Thanks

like image 366
Aubrey L. Obrien Avatar asked Mar 14 '23 09:03

Aubrey L. Obrien


1 Answers

I've updated your code: http://jsfiddle.net/d3ruexuv/1/

The text isn't clearing because you were only appending the items to the current value, not creating a new string altogether. You can see now that an empty string is always created first:

var newText = "";

and selected items concatenated to that

like image 108
millerbr Avatar answered Mar 25 '23 07:03

millerbr