fnaticRC ggwp fnaticRC ggwp - 10 months ago 38
Javascript Question

UnCaught Reference: variable is not defined

I need to keep track of counter while using ng-repeat module.
I have a counter set before the ng-repeat code as :

<script type="text/javascript" var counter = 0;></script>

Then come my important code :
<div class= "col-md-4" ng-repeat="coffeedata in coffecataloge">
<img id="product-images" style="margin-top:20px;margin-left:30px;width:50px;height:50px"/>
<script type="text/javascript" >
counter += 1;

Now the thing is I get an error when I am trying to increment the value of counter saying "Uncaught ReferenceError: counter is not defined"

Any idea how can I achieve my task ?


This is not valid html, nor is it javascript:

<script type="text/javascript"  var counter = 0;></script>

You should put the var counter = 0; inside the script tag, same as you did with the second script:

<script type="text/javascript">
  var counter = 0;