Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Is there a way to set the initial value of a variable in view? What I mean is:
<div> {{ myVar = 2 }} </div>
So that myVar is now set to 2, and I can access it via $scope.myVar as well 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 accessible via $scope.myVar in your controller.
Add a comment
To Concatenate the two variable value using delimiter/underscore(_) in HTML using AngularJS
<div ng-init="item_id = (variable_1 + '_' + variable_1)"></div>
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.