0

私はAngularの経験があまりなく、コードがこのように動作する理由を理解できません..工場からデータを取得するコントローラーと、それを表示するモーダルがあります。渡された 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