嵌套的ng-repeats无法从父ng-repeat获取数据

时间:2016-02-26 00:46:47

标签: html angularjs json angularjs-ng-repeat

我对角度很新,我尝试循环嵌套重复。我的HTML看起来像:

<div class="alert alert-warning" ng-repeat = "producer in producers" >
        <div ng-init="beers=producer.beer"> {{  producer.producer }}</div>
        <div> {{beers}}</div> <!-- Returns proper json -->
            <div class="row row-same-hight">
                <div ng-repeat "beer in beers"> <!-- does not loop -->
                    <div class="col-sm-8" col-xs-height>
                        <div class="list-group">
                                <h4 class="list-group-item-heading beer-name"> {{ beer.product.name | uppercase }}</h4>
                        </div>
                    </div>
                    <div class="col-sm-2" col-xs-height>
                        <div class="list-group">
                            <h4 class="list-group-item-heading">Six Pack: {{ beer.product.price | currency }}</h4>
                        </div>
                    </div>
                </div>
        </div>  

“啤酒中的重复啤酒”部分没有循环。但是,变量啤酒包含以下json:

[{"plu":87692000495,"type_fk":403,"producer_fk":"Sam Adams","description":"No description avalible","single_fk":null,"product":{"plu":87692000495,"price":9.5,"name":" Double Agent IPL 6 Pk"}},{"plu":87692001058,"type_fk":403,"producer_fk":"Sam Adams","description":"No description avalible","single_fk":null,"product":{"plu":87692001058,"price":15.47,"name":" Boston Lager 12 Pk Can"}},{"plu":87692001270,"type_fk":403,"producer_fk":"Sam Adams","description":"No description avalible","single_fk":null,"product":{"plu":87692001270,"price":9.5,"name":" Rebel IPA 6 pk"}},{"plu":87692100126,"type_fk":403,"producer_fk":"Sam Adams","description":"No description avalible","single_fk":null,"product":{"plu":87692100126,"price":9.5,"name":" Boston Lager 6pk"}},{"plu":87692111023,"type_fk":403,"producer_fk":"Sam Adams","description":"No description avalible","single_fk":null,"product":{"plu":87692111023,"price":9.5,"name":" Light 6 pk"}},{"plu":87692271024,"type_fk":403,"producer_fk":"Sam Adams","description":"No description avalible","single_fk":null,"product":{"plu":87692271024,"price":9.5,"name":" Cherry Wheat 6 pk"}},{"plu":87692781028,"type_fk":403,"producer_fk":"Sam Adams","description":"No description avalible","single_fk":null,"product":{"plu":87692781028,"price":9.5,"name":" Blackberry Witbier 6 pk"}}]

这对我来说很好看。我不确定为什么ng-repeat没有循环遍历那些数据。

1 个答案:

答案 0 :(得分:1)

ng-repeat "beer in beers"

应该是

ng-repeat="beer in beers"