Is there a way to set the initial value of a variable? I mean:
<div> {{ myVar = 2 }} </div>
So, myVar now set to 2, and I can access it through $scope.myVar when I want and change its value.
myVar
$scope.myVar
Use the ngInit directive:
ngInit
<div ng-init="myVar = 2"> {{ myVar }} </div>
Your value will be initialized and available through $scope.myVar in your controller.
To combine two variable values ββusing delimiter / underscore (_) in HTML using AngularJS
<div ng-init="item_id = (variable_1 + '_' + variable_1)"></div>