简体   繁体   中英

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;
</script>
</div>

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;
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM