JavaScript How to register order of checkboxes in AngularJS?

I currently have a list of checkboxes in my webapp. I want to show the order in which the checkboxes have been checked. So I wrote the code below.

$scope.updateNumbers = function(id, checked, inputs) {
    if (checked === true) {
        $scope.count += 1;
        var span = angular.element('#'+id+'-'+id);
        span.html($scope.count);
    } else {
        if ($scope.count != 0) {
            $scope.count -= 1;
        }

        for (index = 0; index < inputs.length; ++index) {
            var input = inputs[index];

            var span = angular.element('#'+test.id+'-'+test.id);
            if (span.html() > $scope.count || span.html() == $scope.count) {
                span.html(span.html()-1);
            }
        }

        var span = angular.element('#'+id+'-'+id);
        span.html($scope.count);
    }
}

And this HTML

<div class="list-view__body__row" ng-repeat="restaurant in restaurants">
    <div class="list-view__body__cell">
        <input type="checkbox" id="<% restaurant.id %>" value="" 
          class="input-field__checkbox--input" 
          ng-model="restaurant.checked" 
          ng-change="updateNumbers(restaurant.id, restaurant.checked, restaurants)">
        <label for="<% restaurant.id %>" 
          class="input-field__checkbox--label" 
          ng-bind-html="restaurant.name|html"></label>
    </div>
    <div class="list-view__body__cell">
        <div class="order__wrapper" ng-show="restaurant.checked">
            <span id="<% restaurant.id %>-<% restaurant.id %>">0</span>
        </div>
    </div>
</div>

In the current implementation, though, sometimes the number will go down to 0 or numbers will appear twice. It's not working correctly, so how can I improve on this code?

Answer:1

So I have this: const Link = styled.a` color: blue; `; <Wrapper> <Link href="/">Hover Change</Link> <Wrapper> I want to put a hover effect on just the Link element ...

So I have this: const Link = styled.a` color: blue; `; <Wrapper> <Link href="/">Hover Change</Link> <Wrapper> I want to put a hover effect on just the Link element ...

  1. hover styled component
  2. hover state styled components
  3. button hover styled components
  4. styled component hover parent
  5. styled component hover react
  6. styled component hover effect
  7. hover styled components

I want to add an image to the legend of a pie in Highcharts Yii2. See example but I cannot write it into my PHP widget in the labelFormat section. <? = \dosamigos\highcharts\HighCharts::widget([ ...

I want to add an image to the legend of a pie in Highcharts Yii2. See example but I cannot write it into my PHP widget in the labelFormat section. <? = \dosamigos\highcharts\HighCharts::widget([ ...

The new spread syntax can be used to elegantly merge several objects in the following way: const person = { name: 'David Walsh', gender: 'Male' }; const tools = { computer: 'Mac', editor: 'Atom' }; ...

The new spread syntax can be used to elegantly merge several objects in the following way: const person = { name: 'David Walsh', gender: 'Male' }; const tools = { computer: 'Mac', editor: 'Atom' }; ...

I want to use the selector in document.querySelector() to select all a tags with the text "print". <a href="https://www.google.co.in">print</a> how can I select the same. I don't want to ...

I want to use the selector in document.querySelector() to select all a tags with the text "print". <a href="https://www.google.co.in">print</a> how can I select the same. I don't want to ...

  1. select anchor tags html
  2. select anchor tags using jquery
  3. select anchor tag in jquery
  4. select anchor tag with class jquery
  5. select anchor tag with text jquery
  6. select anchor tag with id in jquery
  7. select anchor tag javascript
  8. select anchor tag in selenium
  9. select anchor tag
  10. select anchor tag with text javascript
  11. select anchor tag xpath
  12. select all anchor tags in jquery
  13. select all anchor tags javascript
  14. select all anchor tags
  15. jquery select anchor tag with href
  16. select option anchor tag
  17. jquery select anchor tag within div
  18. select last anchor tag
  19. select dropdown anchor tag
  20. xpath select all anchor tags