samedi 19 septembre 2015

Checked checkbox ng-change not firing first time

This is my code:

$scope.toggleBandPics = function(bandid){
    for (var picid in $scope.bands[bandid]['pics']) {
        $scope.bands[bandid]['pics'][picid]['show'] = ($scope.bands[bandid]['pics'][picid]['show'] == 'true'? 'false': 'true');
    }
}
<span ng-repeat="band in bands">
    <div class="bandsfilter">
            <span ng-show="bButtons">
                    <input class="checkbox"
                        name="{{band.urlbandname}}"
                        type="checkbox"
                        id="{{band.urlbandname}}"
                        ng-model="band.checked"
                        ng-checked="{{band.checked}}==true"
                        ng-true-value="{{band.checked}}==true"
                        ng-false-value="{{band.checked}}==false"
                        ng-change="toggleBandPics({{band.bandid}})"
                        />
                        {{band.bandname}}&nbsp;({{band.noOfPicsPerBand}})
                            <span id="counter{{band.bandid}}" class="hidden">
                    {{band.noOfPicsPerBand}}
            </span>
                <span>
        </div>
</span>
<span ng-repeat="band in bands">
    <span ng-repeat="picture in band.pics">
            <div class='picture' ng-show="picture.show=='true'" ng-cloack>
                    <a class="shadowbox{{picture.bandid}} photo" rel="shadowbox[{{humanconcertdate}}]" title="{{picture.bandname}}, {{humanconcertdate}}, {{venuename}}" href="/concert2/{{band.concertid}}/{{band.bandid}}/{{picture.filename}}">
                                <img src="/concert2/{{picture.concertid}}/{{picture.bandid}}/{{picture.filename}}" alt="{{picture.bandname}}, {{humanconcertdate}}, {{venuename}}" />
            </a>
        </div>
    </span>
</span>

Now, when I run this ng-change is fired except for the first time that a checked checkbox is unchecked. When it is checked again (so when it is clicked for the second time) it does fire.




Aucun commentaire:

Enregistrer un commentaire