Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ng-click and ng-model - what comes first?
Message
From
22/10/2014 06:58:57
John Baird
Coatesville, Pennsylvania, United States
 
General information
Forum:
Javascript
Category:
Other
Miscellaneous
Thread ID:
01609730
Message ID:
01609749
Views:
47
>>>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.
>>
>>If it works... that should be good enough for you... When have you ever cared about best practice?
>
>I do care about it. Looks like you're on the roll and jump into each of my threads last few days. Do you know the answer to my question?

I've answered one already, time for you to do a little of your own work...
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform