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.
Use the ngInit
directive:
<div ng-init="myVar = 2"> {{ myVar }} </div>
Your value will be initialized, and accessible via $scope.myVar
in your controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With