例如,我希望在递归脚本中有一个计数器来计算脚本被调用的次数。
但是,而不是打印
1
2
3
...
我正在
1
1
1
...
这是我的模板代码:
<div ng-app="App" ng-controller="ctrl">
<div>
<div ng-include="'temp.html'" onload="counter=counter"></div>
</div>
<script type="text/ng-template" id="temp.html">
<h3> {{counter+1}} </h3>
<div ng-include="'temp.html'" onload="counter=counter"></div>
</script>
</div>
这是我的JSFiddle:http://jsfiddle.net/tp2tuwyy/1/
答案 0 :(得分:0)
只需更新
<h3> {{counter = counter + 1}} </h3>
答案 1 :(得分:0)
按以下方式更新HTMl
<div ng-app="App" ng-controller="ctrl">
<div>
<div ng-include="'temp.html'" onload="counter=counter"></div>
</div>
<script type="text/ng-template" id="temp.html">
<h3> {{counter}} </h3>
<div ng-include="'temp.html'" onload="counter=counter+1"></div>
</script>
</div>
此致