0

我对角度不是很有经验,我只是不知道为什么我的代码会这样。我有一个控制器,它从工厂获取数据和一个模态来显示它。它根据传递的 id 返回正确的数据,但在 ng-repeat 之后,它仅加载第一条记录的数据或不加载:

`

<div ng-controller="TokensCtrl"><a href="#tokensModal" type="button" class="btn" data-toggle="modal" ng-click="getTokens(child.ChildId)" ng-model="child.ChildId">Get Tokens{{child.ChildId}}</a>
                <div id="tokensModal" class="modal fade tokens" tabindex="-1" role="dialog" aria-hidden="true">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h3>Tokens:</h3>
                    </div>
                    <div class="modal-body">
                        <ul ng-repeat='token in tokens'>
                            <li><input value={{token}} /></li>
                        </ul>{{tokens}} <!--the first record set of tokens on every iteration -->
                    </div>
                    <div class="modal-footer">
                        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
                    </div>
                </div>
            </div>

the controller, that returns the right data:

app.controller('TokensCtrl',
    function ($scope, tokens) {
        $scope.status;
        $scope.test = 'testing';

        $scope.getTokens = function (id) {
            console.log(id + "controller");
            tokens.getTokens(id)
                .success(function (tokens) {
                    $scope.tokens = tokens;
                    console.log($scope.tokens);// here i can see it returns the right set of tokens
                })
                .error(function (error) {
                    $scope.status = "Unable to get tokens: " + error.message;
                })
        }
    }
)

`

我认为这可能是一个愚蠢的错误,但我只是看不到它.. 或者没有

4

1 回答 1

1

尝试将 ng-repeat 指令放在li标签而不是ul中。

于 2013-11-12T06:00:59.073 回答