Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ng-click and ng-model - what comes first?
Message
 
 
À
22/10/2014 01:44:57
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01609730
Message ID:
01609753
Vues:
36
>>Hi everybody,
>>
>>I implemented the following code
>>
>>
>> <div class="checkbox">
>>        <label>
>>            <input type="checkbox" name="showFinalized" id="showFinalized"
>>                   ng-model="showFinalized"
>>                   ng-click="getAccountInvoices(currentAccount.acctNameHash)" />Show Finalized Invoices
>>        </label>
>>    </div>
>>
>>and I am using $scope.showFinalized in the getAccountInvoices method. However, at that point the value of this variable is opposite, e.g. I click on the checkbox and my value is supposed to be true, but the method receives false instead.
>>
>>What is the right way to handle this problem?
>>
>>Thanks a lot in advance.
>>
>>UPDATE. The way I solved the problem is to remove ng-click and use the following code instead:
>>
>>
>>$scope.$watch('showFinalized', function () {
>>                    if ($scope.currentAccount && !$scope.isNew) {
>>                        getAccountInvoices($scope.currentAccount.acctNameHash);
>>                    }
>>                });
>>
>>This seems to work well. Not sure if this is a good practice or not, though.
>
>I think that using ng-change rather than ng-click in you original code should work ?

My colleague also suggested ng-change, but for some strange reason ng-change did absolutely nothing and was not even firing.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform