angularjs如何在没有onclick的情况下增加ng-repeat中的init变量值?

前端之家收集整理的这篇文章主要介绍了angularjs如何在没有onclick的情况下增加ng-repeat中的init变量值?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在ng-repeat中增加init变量值
<div ng-if="FeedData.carouselMode == true" ng-init='start=0'  ng-repeat="a in carousel_data">

            <div  class="owl-demo" class="owl-carousel"   owl-carousel >
            <div class="item"  ng-repeat="(key,item) in a.carouselFeeds" ng-init="start=start+1">
                {{start}}
                <div ng-click="go('{{key}}',item.FeedUrls.length,'rtl')" ng-swipe-left="go('{{key}}','rtl')">
            <img class="lazyOwl"  ng-src="{{item.img}}"  />  
            <span class="innersquare" image-ja="{{item.img}}"> 
                <p ng-style="folderStyle">{{item.name  }}&nbsp;</p> </span>
                 </div> 
            </div>
        </div>
    </div>

增量开始后ng-init start = 0 = ng-repeat中的start 1但没有count只显示1.

这是因为每个ng-repeat都有自己的范围,每个ng-init只会增加自己的范围变量.您可以尝试使用$parent访问父作用域.

如果您正在寻找连续计算,请尝试这样做

<div ng-controller="MyCtrl">
<div ng-repeat="a in ['a','b','c']" ng-init="current = $parent.start; $parent.start=$parent.start+3;">
        <div ng-repeat="x in ['alpha','beta','gamma']">
            {{current + $index}}
    </div>
</div>

3应该是[内部阵列的长度].

http://jsfiddle.net/rvgvs2jt/2/

对于您的特定代码,它看起来像这样

<div ng-if="FeedData.carouselMode == true" ng-init='current=$parent.start; $parent.start=$parent.start+a.carouselFeeds.length' ng-repeat="a in carousel_data">
    <div class="owl-demo" class="owl-carousel" owl-carousel>
        <div class="item" ng-repeat="(key,item) in a.carouselFeeds">
            {{current + $index}}
            <div ng-click="go('{{key}}','rtl')">
                <img class="lazyOwl" ng-src="{{item.img}}" />
                <span class="innersquare" image-ja="{{item.img}}"> 
                <p ng-style="folderStyle">{{item.name  }}&nbsp;</p> </span>
            </div>
        </div>
    </div>
</div>
原文链接:https://www.f2er.com/angularjs/142482.html

猜你在找的Angularjs相关文章