简体   繁体   中英

Checkbox: make ng-click run when checked by ng-checked/ng-model

So i have this:

<tbody ng-repeat="x in keys">
    <tr>
        <td>
            <input type="checkbox" ng-model="master">
            {{ x.key }}
        </td>
        <td ng-repeat="lang in languages">
            {{ getTranslation(x,lang.id) }}
            <input type="checkbox" ng-click="toggleSelection(x,lang.id)" ng-model="master">
        </td>
    </tr>
</tbody>

my problem is that if i check the first checkbox, my other checkboxes will be checked without running the ng-click. How can i make the ng-click run when the checkboxes gets checked via the first one? I tried with ng-change as well.

the "ng-change" directive should be ok. try this Example:

    <script>
        angular.module('changeExample', [])
            .controller('ExampleController', ['$scope', function($scope) {
                $scope.counter = 0;
                $scope.change = function() {
                    $scope.counter++;
                };
            }]);
    </script>
    <div ng-controller="ExampleController">
        <input type="checkbox" ng-model="confirmed" ng-change="change()" id="ng-change-example1" />
        <input type="checkbox" ng-model="confirmed" id="ng-change-example2" />
        <label for="ng-change-example2">Confirmed</label><br />
        <tt>debug = {{confirmed}}</tt><br/>
        <tt>counter = {{counter}}</tt><br/>
    </div>

you can find this here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM