Reputation: 571
The AngularJS docs only list four differences between Angular expressions and JS expressions (docs):
undefined
and null
);But arithmetic assignment operators also don't work inside an expression. For example, "plus-equals" +=
and "minus-equals" -=
raise an error on the constant after the equals-sign.
Is there a particular reason why these assignment operators would be problematic to allow in expressions? Or would this simply be a matter of implementation priorities?
Is there perhaps an Angular-specific way of incrementing and decrementing? Currently, people seem to be left to typing the full somelongname = somelongname + x
, or defining increment and decrement as functions in a controller. The same goes for other arithmetic assignment operators.
A short example of what I'm using to increment and decrement as workaround. It works, but is it elegant?
In controller:
$scope.incr = function(number, constant){
$scope[number] += constant;
};
$scope.decr = function(number, constant){
$scope[number] -= constant;
};
In HTML:
<button class="btn" ng-disabled="currentPage == 0" ng-click="decr('currentPage', 1)">
Upvotes: 2
Views: 3778
Reputation: 364707
Is there a particular reason why these assignment operators would be problematic to allow in expressions? Or would this simply be a matter of implementation priorities?
I would say it is a combination of
Upvotes: 1