You just need to expose your variables as fields in your scope.
$scope.total1 = 0;
$scope.total2 = 0;
That should suffice, no need to return anything.
Question
Starting to learn angularjs I'm trying some simple examples. I want in my view 2 variables total1 en total2, which are calculated in a function in my js.
my js
var total1 = 0;
var total2 = 0;
// Use the angular forEach helper method to
// loop through the services array:
angular.forEach($scope.services, function(s){
if (s.active){
total1+= s.price;
total2+= 1;
}
});
return [total1, total2];
};
my html
<div class="total">
<!-- Calculate the total price of all chosen services. Format it as currency. -->
Totaal: <span>{{total1 | currency:"€ "}}</span>
Selected: <span>{{total2 | currency:"€ "}}</span>
</div>
Is there a way to show the variables in the view withing angular, using somehing like the {{my_var1}} {{my_var2}}
Solution
You just need to expose your variables as fields in your scope.
$scope.total1 = 0;
$scope.total2 = 0;
That should suffice, no need to return anything.