1

I'm attempting to perform two operations on ng-click. Currently it is performing one. On my javascript side, I have a variable totalMoviesWatched I'd like to increment on ng-click as well.

 <tr ng-repeat="movie in MovieDB.movies" ng-show="movie.Response == 'True'" ng-class="{ 'strikeout': movie.watched }" >
 <td><a ng-click="movie.watched = true"><span class="glyphicon glyphicon-ok" aria-hidden="true" ng-hide="movie.watched"></span></a></td>

So, something like:

<a ng-click="movie.watched = true, totalMoviesWatched += 1">

??

Thanks!

2 Answers 2

5

Use a semi-colon to separate statements:

<a ng-click="movie.watched = true; totalMoviesWatched = totalMoviesWatched + 1"> <!--Angular can't figure out += inline-->

Or just do both of these operations inside one function:

$scope.myFunc = function() {
    $scope.movie.watched = true;
    $scope.totalMoviesWatched++;
}

<a ng-click="myFunc()">
Sign up to request clarification or add additional context in comments.

4 Comments

I also thought about this, but looks like Angular can't parse += 1 part for some reason.
@dfsq -- Gah - hate that...it also can't do indexOf if you ever come across that :D - editing...
Anyway, your second version ng-click="myFunc()" is even better, keep template cleaner as to me.
so, this is actually not working. only the function that is declared first executes.
2

You should be able to do it using this expression:

ng-click="movie.watched = true; totalMoviesWatched = totalMoviesWatched + 1"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.