我尝试在ng-click上执行两项操作。目前正在执行一项。在我的javascript方面,我有一个变量 totalMoviesWatched 我也希望增加ng-click。
<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>
所以,比如:
<a ng-click="movie.watched = true, totalMoviesWatched += 1">
...
谢谢!
答案 0 :(得分:5)
使用分号分隔语句:
<a ng-click="movie.watched = true; totalMoviesWatched = totalMoviesWatched + 1"> <!--Angular can't figure out += inline-->
或者只在一个函数中执行这两个操作:
$scope.myFunc = function() {
$scope.movie.watched = true;
$scope.totalMoviesWatched++;
}
<a ng-click="myFunc()">
答案 1 :(得分:2)
您应该可以使用以下表达式执行此操作:
ng-click="movie.watched = true; totalMoviesWatched = totalMoviesWatched + 1"