Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sum up two Scope values in AngularJS

var selPage2 = $scope.selPage + $scope.itemsPerPage;
$scope.selPageUp = selPage2;

for example if value of selPage is 50 and value of itemsPerPage is 10 and I want to display my value in HTML element like

{{selPageUp}}

Angular JS will make connection of this two strings and will display it like 5010, but I want to sum up two values to display number 60. How to do that? Example if I change operator from + to * it will multiply value and display 500 it will work on way I want. Help please?

like image 218
Zvonimir Tokic Avatar asked Feb 05 '26 19:02

Zvonimir Tokic


1 Answers

If they are integers:

var selPage2 = parseInt($scope.selPage) + parseInt($scope.itemsPerPage);

Otherwise:

var selPage2 = parseFloat($scope.selPage) + parseFloat($scope.itemsPerPage);
like image 83
Norbor Illig Avatar answered Feb 09 '26 09:02

Norbor Illig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!